POJ grids 2692

http://poj.grids.cn/problem?id=2692
利用枚举,从'A'到'L'。判断条件是:如果是'even',则天平两边无假币;如果是'up',若为light,则假币一定在天平右侧,若为heavy,则假币一定在天平左侧;如果是'down',情况相反。
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 char left[3][7],right[3][7],result[3][5];
 5 bool isLight(char c);
 6 bool isheavy(char c);
 7 int main()
 8 {
 9     int n;
10     while(scanf("%d",&n) != EOF){
11         while(n--){
12             for(int i = 0;i < 3;i++)
13                 scanf("%s%s%s",left[i],right[i],result[i]);
14             char x;
15             for(x = 'A';x <= 'L';x++){
16                 if(isLight(x)){
17                     printf("%c is the counterfeit coin and it is light.\n",x);
18                     break;
19                 }
20                 if(isheavy(x)){
21                     printf("%c is the counterfeit coin and it is heavy.\n",x);
22                     break;
23                 }
24             }
25         }
26     }
27     system("pause");
28     return 0;           
29 }
30 
31 bool isLight(char c)
32 {
33     for(int i = 0;i < 3;i++){
34         if(!strcmp(result[i],"even"))
35             if(strchr(left[i],c) != NULL || strchr(right[i],c) != NULL)return false;
36         if(!strcmp(result[i],"up"))
37             if(strchr(right[i],c) == NULL)return false;
38         if(!strcmp(result[i],"down"))
39             if(strchr(left[i],c) == NULL)return false;
40     }
41     return true;
42 }
43 
44 bool isheavy(char c)
45 {
46     for(int i = 0;i < 3;i++){
47         if(!strcmp(result[i],"even"))
48             if(strchr(left[i],c) != NULL || strchr(right[i],c) != NULL)return false;
49         if(!strcmp(result[i],"up"))
50             if(strchr(left[i],c) == NULL)return false;
51         if(!strcmp(result[i],"down"))
52             if(strchr(right[i],c) == NULL)return false;
53     }
54     return true;
55 }
56 

posted on 2009-07-18 14:09 Johnnx 阅读(337) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

统计

常用链接

留言簿(1)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜