#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
const int WEIGHT = 2;//标准银元重量为2
int getWeight(string s,char ch,int w)//ch为假银元,重量为1或3
{
size_t pos = s.find(ch);
if(pos == string::npos)
return s.size()*WEIGHT;
return (s.size()-1)*WEIGHT+w;
}
int main()
{
freopen("in.txt","r",stdin);
int n;//n > 0
cin>>n;
string left[3],right[3],result[3];
int lw,rw;
string s;
while(n--)
{
cin>>left[0]>>right[0]>>result[0]
>>left[1]>>right[1]>>result[1]
>>left[2]>>right[2]>>result[2];
char ch;
int w,i;
for(ch = 'A'; ch <= 'L'; ++ch)
{
for(w = 1; w <= 3; w += 2)
{
for(i = 0; i < 3; ++i)
{
lw = getWeight(left[i],ch,w);
rw = getWeight(right[i],ch,w);
if(lw == rw)s = "even";
else if(lw < rw) s = "down";
else s = "up";
if(s != result[i])
break;
}
if(i == 3)
{
s = (w == 1)?"light":"heavy";
cout<<ch<<" is the counterfeit coin and it is "<<s<<"."<<endl;
goto END;
}
}
}
END:
;
}
}
这个题目直接进行枚举就可以了,迭代次数也不多,对于每一个实例最多12*2*3次,很快。