POJ_1013,秤假币问题,参考这里
#include <iostream>
#include <string.h>
using namespace std;
int main(){
int num;
int weight[12];
string left,right,result;
for(cin>>num;num!=0;num--){
memset(weight,0,sizeof(weight));
for(int i=0;i<3;i++){
cin>>left>>right>>result;
if(result=="even"){
for(int j=0;j<left.size();j++){
weight[left[j]-'A']=2;
weight[right[j]-'A']=2;
}
}
else{
bool flag[12];
memset(flag,0,sizeof(flag));
if(result=="up"){
for(int j=0;j<left.size();j++){
flag[left[j]-'A']=1;
flag[right[j]-'A']=1;
if(weight[left[j]-'A']==0) weight[left[j]-'A']=3;
if(weight[left[j]-'A']==1) weight[left[j]-'A']=2;
if(weight[right[j]-'A']==0) weight[right[j]-'A']=1;
if(weight[right[j]-'A']==3) weight[right[j]-'A']=2;
}
for(int j=0;j<12;j++){
if(flag[j]==0) weight[j]=2;
}
}
else{
for(int j=0;j<left.size();j++){
flag[left[j]-'A']=1;
flag[right[j]-'A']=1;
if(weight[left[j]-'A']==0) weight[left[j]-'A']=1;
if(weight[left[j]-'A']==3) weight[left[j]-'A']=2;
if(weight[right[j]-'A']==0) weight[right[j]-'A']=3;
if(weight[right[j]-'A']==1) weight[right[j]-'A']=2;
}
for(int j=0;j<12;j++){
if(flag[j]==0) weight[j]=2;
}
}
}
}
for(int i=0;i<12;i++){
if(weight[i]==1){
cout<<char(i+'A')<<" is the counterfeit coin and it is light."<<endl;
break;
}
if(weight[i]==3){
cout<<char(i+'A')<<" is the counterfeit coin and it is heavy."<<endl;
break;
}
}
}
return 0;
}