题目链接:http://poj.org/problem?id=1013

解题报告:

1、由于次品的重量不清楚,用time['L'+1]来记录各个字母被怀疑的次数。为负数则轻,为正数则重。

2、用zero['L'+1]记录当天平结果是even时,硬币绝对是真,true;

#include <iostream>
#include <cmath> using namespace std; int main()
{
int t;
cin>>t;
while(t--)
{
char left[][],right[][],result[][]; int time['L'+]= {}; ///标记各个字母被怀疑的次数;
bool zero['L'+]= {false}; ///标记字母绝对是真币; for(int k=; k<; k++)
cin>>left[k]>>right[k]>>result[k]; for(int i=; i<; i++) ///3次判断
{
///检查天平状态
switch(result[i][])
{
case 'e':///天平平衡
{
for(int j=; left[i][j]!='\0'; j++)
{
zero[left[i][j]]=true; zero[right[i][j]]=true;
}
break;
}
case 'u':///天平右边轻些
{
for(int j=; left[i][j]!='\0'; j++)
{
time[left[i][j]]++; time[right[i][j]]--;
}
break;
}
case 'd':///天平右边重些
{
for(int j=; left[i][j]!='\0'; j++)
{
time[left[i][j]]--; time[right[i][j]]++;
}
break;
}
}
} int Max=-;///查找被怀疑程度最高的硬币
char alpha;
for(int j='A';j<='L';j++)
{
if(zero[j])
continue; if(Max<=abs(time[j]))
{
Max=abs(time[j]);
alpha=j;
}
}
cout<<alpha<<" is the counterfeit coin and it is ";
if(time[alpha]>)
cout<<"heavy.\n";
else cout<<"light.\n";
}
return ;
}
05-04 04:38