|
|
思路:逐一判断每个金币是否为真。
1,当天平为oven 时,里面的金币都为真;
2,天平不是oven时,假的金币在天平了,不在里面的都为真(没想到这点~~看报告所得!),同时将天平里的金币标记。分为轻和重。
3,当一个金币既是轻,又是重时,是真的。
输出为假的金币。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;bool vis[14];class tt{public:int t;bool light,weight;tt (){t=-1;light=false ;weight=false;}};char up[7]="up",down[7]="down",over[7]="even";class node{public:char a[7],b[7],c[7];};node st[4]; int main(){int i,j,n,l1,l2,k;cin>>n;char ch;while(n--){tt co[14];for( i=0;i<3;i++){scanf("%s%s%s",&st[i].a,&st[i].b,&st[i].c );if(strcmp(st[i].c ,over)==0){l1=strlen(st[i].a );for(j=0;j<l1;j++)co[st[i].a [j]-'A'].t =0;l1=strlen(st[i].b );for(j=0;j<l1;j++)co[st[i].b [j]-'A'].t =0;}else if(strcmp(st[i].c ,up)==0){memset(vis,false ,sizeof(vis));l1=strlen(st[i].a );for(j=0;j<l1;j++){k=st[i].a[j]-'A';vis[k]=true;if(co[k].t ==-1){co[k].weight =true;}}l1=strlen(st[i].b );for(j=0;j<l1;j++){k=st[i].b [j]-'A';vis[k]=true;if(co[k].t ==-1){co[k].light =true;}}for(j=0;j<12;j++)if(!vis[j])co[j].t=0;}else {memset(vis,false ,sizeof(vis));l1=strlen(st[i].a );for(j=0;j<l1;j++){k=st[i].a[j]-'A';vis[k]=true;if(co[k].t ==-1){co[k].light =true;}}l1=strlen(st[i].b );for(j=0;j<l1;j++){k=st[i].b [j]-'A';vis[k]=true;if(co[k].t ==-1){co[k].weight =true;}}for(j=0;j<12;j++)if(!vis[j])co[j].t=0;}}for(i=0;i<12;i++){if(co[i].light &&co[i].weight ){co[i].t =0;}if(co[i].t ==-1){if(co[i].light )printf("%c is the counterfeit coin and it is light.\n",i+'A');else printf("%c is the counterfeit coin and it is heavy.\n",i+'A');break;}}}return 0;} |
|