There is a coin with a A-L label, one of which is a coin, you do not know the weight of the coin, now give you three strings, up represents the right light, down the right heavy, even indicates that the two sides are equal. Identify the counterfeit currency and judge the severity.
Idea: Because only A-L coins So enumeration, assuming a is counterfeit currency, and then judge whether to meet the three conditions, meet the conditions of the Preservation
How does one satisfy the conditions? Except for those that do not meet the conditions, all the remaining conditions are met.
Not meeting the conditions
1. Assume that the strings with the same two sides contain coins.
2. The character string on the right is light on the left or heavy on the right, which means the assumption is not true.
3. The character string with the weight on the right may appear on the left or on the right, indicating that the assumption is not true.
If the above conditions are not met, the counterfeit currency is used.
#include<iostream>#include<cstdio>#include<cstring>using namespace std;char L[3][10];char R[3][10];char heav[3][10];struct coin{ char c; int flag;};int main(){ int t; scanf("%d",&t); while(t--) { int i,j; for(i = 0; i < 3; i++) { scanf("%s%s%s",L[i],R[i],heav[i]); } coin a;a.c = 'A',a.flag = -1; int f; for(i = 0; i < 12; i++) { int flag_L = 0,flag_R = 0;f = -1; for(j = 0; j < 3; j++) { flag_L = 0,flag_R = 0; int len; int len_L = strlen(L[j]),len_R = strlen(R[j]); for(len = 0; len < len_L; len++) { if((i+'A') == L[j][len]) flag_L = 1; } for(len = 0; len < len_R; len++) { if((i+'A') == R[j][len]) flag_R = 1; } if(strcmp(heav[j],"even") == 0 ) { if(flag_L || flag_R) { break; } } else if(strcmp(heav[j],"up") == 0) {//printf("%c\n",i+'A'); if(flag_R && f == 0) break; if(flag_L && f == 1) break; if(!flag_R && !flag_L) break; if(flag_R) { f = 1; } else if(flag_L) { f = 0; } } else if(strcmp(heav[j],"down") == 0) { if(flag_L && f == 0) break; if(flag_R && f == 1) break; if(!flag_R && !flag_L) break; if(flag_L) { f = 1; } if(flag_R) { f = 0; } } } if(j == 3) { a.c = i+'A'; a.flag = f; } } if(a.flag == 0) printf("%c is the counterfeit coin and it is heavy.\n",a.c); else printf("%c is the counterfeit coin and it is light.\n",a.c); } return 0;}