#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
bool ok(char p[3][3][10],int w,char ch) //數組做形參 ,w表示輕重,ch爲枚舉的那枚硬幣
{
int i,j,lw,rw; //lw爲左邊的重量,rw爲右邊的
for(i=0;i<3;i++)
{
lw=0; rw=0; //初值一定要在此處賦!
for(j=0;j<strlen(p[i][0]);j++)
if(p[i][0][j]==ch) lw=w; //處理左邊
for(j=0;j<strlen(p[i][1]);j++)
if(p[i][1][j]==ch) rw=w; //處理右邊
if((p[i][2][0]=='e'&&lw==rw)||(p[i][2][0]=='u'&&lw>rw)||(p[i][2][0]=='d'&&lw<rw)) continue;
else return false; //判斷是否可行
}
return true;
}
int main()
{
char f[3][3][10]; //儲存讀入數據
int i,j,weight,cas,z;
cin>>cas;
for(z=0;z<cas;z++)
{
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
cin>>f[i][j];
if(f[i][j]==" ") j--; //空格字符會影響讀入,如爲空格,此次讀入作廢
}
for(i=0;i<12;i++)
for(weight=-1;weight<=1;weight+=2) //wight,-1爲輕,1爲重
if(ok(f,weight,char('A'+i)))
{
cout<<char('A'+i)<<" is the counterfeit coin and it is ";
if(weight<0) cout<<"light."<<endl;
else cout<<"heavy."<<endl;
break;
}
}
return 0;
}
poj1013 Counterfeit Dollar 稱硬幣
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.