| ||||||||||
| 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 | |||||||||
我的代码In Reply To:Re:出人命了!测试数据都对了可wrong了N次:大侠几个让我wrong的数据或建议吧,不胜感激: Posted by:gordon007 at 2009-06-21 18:52:49 #include <iostream>
#include<string.h>
using namespace std;
struct
{
int q;
int z;
int d;
int f;
} flag[26];
int main()
{
int t,i,j,loop,len1,len2,ans;
char L[15],R[15],d1[15];
while(cin>>t&&t){
while(t--)
{
memset(flag,0,sizeof(flag));
loop=0;
for(j=0;j<3;j++)
{
cin>>L>>R>>d1;
len1=strlen(L);
len2=strlen(R);
if(strcmp(d1,"even")==0)
{
for(i=0;i<len1;i++)
{flag[L[i]-'A'].d++;flag[L[i]-'A'].f=1;}
for(i=0;i<len2;i++)
{flag[R[i]-'A'].d++;flag[R[i]-'A'].f=1;}
}
else if(strcmp(d1,"up")==0)
{
loop++;
for(i=0;i<len1;i++)
flag[L[i]-'A'].z++;
for(i=0;i<len2;i++)
flag[R[i]-'A'].q++;
}
else if(strcmp(d1,"down")==0)
{
loop++;
for(i=0;i<len1;i++)
flag[L[i]-'A'].q++;
for(i=0;i<len2;i++)
flag[R[i]-'A'].z++;
}
}//for
for(i=0;i<12;i++)
{
if(flag[i].f!=1&&(flag[i].q==loop||flag[i].z==loop))
{
ans=i;
if(flag[ans].q==loop)
cout<<char(i+'A')<<" is the counterfeit coin and it is light."<<endl;
else if(flag[i].z==loop)
cout<<char(i+'A')<<" is the counterfeit coin and it is heavy."<<endl;
break;
}
}
}//while
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator