Blog·Tanky WooABOUTRSS

POJ1013 Counterfeit Dollar

15 May 2010
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

枚举,很普通的题目 Memory: 144K Time: 0MS Language: C++ Result: Accepted

#include 
using namespace std;

#define false 0
#define true 1
char left_Bal[3][7], right_Bal[3][7], result[3][7];
bool isLight(char x);
bool isHeavy(char x);

int main()
{
    int nCases;
    char c;
    scanf("%d", &nCases;);
    while(nCases--)
    {
        for(int i = 0; i < 3; i++)
            scanf("%s %s %s", left_Bal[i], right_Bal[i], result[i]);
        for(c = 'A'; c <= 'L'; c++)
        {
            if(isLight(c))
            {
                printf("%c is the counterfeit coin and it is light.\n", c);
                break;
            }
            if(isHeavy(c))
            {
                printf("%c is the counterfeit coin and it is heavy.\n", c);
                break;
            }
        }
    }
    return 0;
}

bool isLight(char x)
{
    int i;
    for(i = 0; i < 3; i++)
        switch(result[i][0])
        {
            case 'u':
                if(strchr(right_Bal[i], x) == NULL)
                    return false;
                break;
            case 'e':
                if(strchr(right_Bal[i], x) != NULL || strchr(left_Bal[i], x) != NULL)
                    return false;
                break;
            case 'd':
                if(strchr(left_Bal[i], x) == NULL)
                    return false;
                break;
        }
    return true;
}

bool isHeavy(char x)
{
    int i;
    for(i = 0; i < 3; i++)
        switch(result[i][0])
        {
            case 'd':
                if(strchr(right_Bal[i], x) == NULL)
                         return false;
                break;
            case 'e':
                if(strchr(right_Bal[i], x) != NULL || strchr(left_Bal[i], x) != NULL)
                    return false;
                break;
            case 'u':
                if(strchr(left_Bal[i], x) == NULL)
                         return false;
                break;
        }
    return true;
}