poj1013 0ms 称硬币

#include<cstdio>
#include<cstring>
using namespace std;
//简单枚举
char left[3][7];//左边天平的砝码
char right[3][7];//右边天平的砝码
char res[3][7];//右边的情况
bool isFake(char c,bool light)
{
//light表示轻重,true为轻
    char *pleft,*pright;
    for(int i = 0; i<3; ++i)
    {
        if(light)
        {
            pleft = left[i];
            pright = right[i];
        }
        else //调换指针,简化switch部分的代码,不然又要根据light再写一个函数
        {
            pleft = right[i];
            pright = left[i];
        }
        switch(res[i][0])
        {
        case 'u':
            if(strchr(pright,c)==NULL)
                return false;
            break;
        case 'd':
            if(strchr(pleft,c)==NULL)
                return false;
            break;
        case 'e':
            if(strchr(pleft,c)||strchr(pright,c))
                return false;
            break;
        }
    }
    return true;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        for(int i = 0; i<3; ++i)
            scanf("%s %s %s",left[i],right[i],res[i]);
        for(char c = 'A'; c<='L'; ++c)
        {
            if(isFake(c,true))
            {
                printf("%c is the counterfeit coin and it is light. \n",c);
                break;
            }
            else if(isFake(c,false))
            {
                printf("%c is the counterfeit coin and it is heavy. \n",c);
                break;
            }
        }
    }
    return 0;
}
全部评论

相关推荐

12-15 19:41
已编辑
广东工业大学 前端工程师
smile丶snow:尽量保证的一张a4纸吧。为什么工作经历只有公司?如果项目经历是工作里面的,应该写到工作经历里的吧。没有写项目职责,项目全是一个人写的吗?标题大小也好怪。两个项目的分割看不出来是,它和那些项目成功字体是一样大的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务