| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为啥会出现Runtime Error呢/*---解题思想就是根据称重,如果重,就对天平上4个加一,轻则减一,最后将平衡中那些变为0,绝对值最大的即为所求;
*/
#include <iostream>
#include <string>
using namespace std;
int data[12]={}; //--装载每个字母的次数
bool nodata[12]={};//--标记平衡状态下的字母
void checkch(string str)
{
if(str[10]!='e')
{
for(size_t i=0;i<9;++i )
{
if(str[i]!=' ')
{
//--根据轻重来-+1;
if((i<4 && str[10]=='u')||(i>4 && str[10]=='d'))
data[str[i]-'A']+=1;
else
data[str[i]-'A']-=1;
}
}
}
else
{
for(size_t i=0;i<9;++i )
{
if(str[i]!=' ')
nodata[str[i]-'A']=true;
}
}
}
int main()
{
int n;
cin>>n;
string str1,str2,str3;
//---不知为什么,这里一定要先getline一次,下面才能顺利的getline
getline(cin,str1);
while(n--)
{
memset(data,0,sizeof(data));
memset(nodata,0,sizeof(nodata));
//--读取数据并检测
getline(cin,str1);
checkch(str1);
getline(cin,str2);
checkch(str2);
getline(cin,str3);
checkch(str3);
//--把data中nodata中装的字母赋为0
for(int i=0;i<12;++i)
{
if(nodata[i]) data[i]=0;
}
//--绝对值最大的那个就是
int max=0,min=0,pos1=0,pos2=0;
for(int i=0;i<12;++i)
{
if(data[i]>max)
{
max=data[i];
pos1=i;
}
else if(data[i]<min)
{
min=data[i];
pos2=i;
}
}
char da='A';
if((max+min)>0)
{
da+=pos1;
cout<<da<<" is the counterfeit coin and it is heavy."<<endl;
}
else
{
da+=pos2;
cout<<da<<" is the counterfeit coin and it is light."<<endl;
}
}
return 0;
}
/*提交答案是Runtime Error*/
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator