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