POJ2692假币问题

聪明的李思思[1元]

Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 12 Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

李思思有12枚银币。其中有11枚真币和1枚假币。假币看起来和真币没有区别,但是重量不同。但李思思不知道假币比真币轻还是重。于是他向朋友借了一架天平。朋友希望李思思称三次就能找出假币并且确定假币是轻是重。例如:如果李思思用天平称两枚硬币,发现天平平衡,说明两枚都是真的。如果李思思用一枚真币与另一枚银币比较,发现它比真币轻或重,说明它是假币。经过精心安排每次的称量,李思思保证在称三次后确定假币。

Input

第一行有一个数字n,表示有n组测试用例。对于每组测试用例: 输入有三行,每行表示一次称量的结果。李思思事先将银币标号为A-L。每次称量的结果用三个
以空格隔开的字符串表示:天平左边放置的硬币 天平右边放置的硬币 平衡状态。其中平衡状态用``up'', ``down'', 或 ``even''表示, 分别为右端高、右端低和平衡。天平左右的硬币数总是相等的。

Output

输出哪一个标号的银币是假币,并说明它比真币轻还是重(heavy or light)。

Sample Input

 1
 ABCD EFGH even 
 ABCI EFJK up 
 ABIJ EFGH even

Sample Output

K is the counterfeit coin and it is light.

Author

tianzuwei 
#include <stdio.h> 
#include <math.h>
#include <stdlib.h>
#include <string.h>
char left[3][7];
char right[3][7];
char cmd[3][7];
bool isheavy(char c)
{
    for(int i = 0 ; i <= 2;i++)
    {
        if(cmd[i][0] == 'e')
    {
        if(strchr(left[i],c)!=NULL||strchr(right[i],c)!=NULL)
           {
           	 return false;break;
		   }
    }
        else if(cmd[i][0] == 'u')
        {
            if(strchr(left[i],c)==NULL) {
           	 return false;break;
		   }
        }
        else if(cmd[i][0] == 'd') 
        {
            if(strchr(right[i],c)==NULL){
           	 return false;break;
		   }
        }
    }
        return true;
}
bool islight(char c)
{
    for(int i = 0 ; i <= 2;i++)
    {
        if(cmd[i][0] == 'e')
        {
            if(strchr(left[i],c)!=NULL||strchr(right[i],c)!=NULL)
            {
           	 return false;break;
		   }
        }
        else if(cmd[i][0] == 'u')
    {
            if(strchr(right[i],c)==NULL) {
           	 return false;break;
		   }
    }
        else if(cmd[i][0] == 'd') 
    {
            if(strchr(left[i],c)==NULL){
           	 return false;break;
		   }
    }
    }
    return true;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        for(int i = 0; i <= 2; i++)
        scanf("%s %s %s",&left[i],&right[i],&cmd[i]);
        for(char ch = 'A';ch <= 'L';ch++)
        {
        	if(islight(ch))
        {
            printf("%c is the counterfeit coin and it is light.\n",ch);
            break;
        }
        else if(isheavy(ch))
        {printf("%c is the counterfeit coin and it is heavy.\n",ch);
        break;
        }
		}
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值