Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 25296 | Accepted: 7872 |
本题因为题意说肯定能够称出来,所以不用担心他是怎么称的,只要对几种情况进行穷举即可
代码:
1 #include<stdio.h>
2 #include<string.h>
3 char a[5][10],b[5][10],c[5][10];
4 int islight(char x)
5 {
6 int i;
7 for(i=1;i<=3;i++)
8 {
9 switch(c[i][0])
10 {
11 case 'u':if(strchr(b[i],x)==NULL) return 0;break;
12 case 'e':if(strchr(a[i],x)!=NULL||strchr(b[i],x)!=NULL) return 0;break;
13 case 'd':if(strchr(a[i],x)==NULL) return 0;break;
14 }
15 }
16 return 1;
17 }
18 int isheavy(char x)
19 {
20 int i;
21 for(i=1;i<=3;i++)
22 {
23 switch(c[i][0])
24 {
25 case 'u':if(strchr(a[i],x)==NULL) return 0;break;
26 case 'e':if(strchr(a[i],x)!=NULL||strchr(b[i],x)!=NULL) return 0;break;
27 case 'd':if(strchr(b[i],x)==NULL) return 0;break;
28 }
29 }
30 return 1;
31 }
32 int main()
33 {
34 int n,i;char t;
35 scanf("%d",&n);
36 while(n--)
37 {
38 for(i=1;i<=3;i++)
39 scanf("%s%s%s",a[i],b[i],c[i]);
40 for(t='A';t<='L';t++)
41 {
42 if(islight(t))
43 {
44 printf("%c is the counterfeit coin and it is light.\n",t);
45 break;
46 }
47 if(isheavy(t))
48 {
49 printf("%c is the counterfeit coin and it is heavy.\n",t);
50 break;
51 }
52 }
53 }
54 return 0;
55 }
56
57