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 |
路过的给看一下#include<stdio.h> #include<string.h> void main() { int i,n,j,k; char s1[10],s2[10],s3[10]; int s[20]; scanf("%d",&n); for(i=1;i<=n;i++) { memset(s,0,sizeof(s)); for(j=1;j<=3;j++) { scanf("%s%s%s",s1,s2,s3); if(strcmp(s3,"even")==0)//如果even,置为1,其为真币 { for(k=0;s1[k]!=0;k++) { s[s1[k]-'A']=1; s[s2[k]-'A']=1; } } if(strcmp(s3,"up")==0) { for(k=0;s1[k]!=0;k++) { if(s[s2[k]-'A']!=1) { if(s[s2[k]-'A']==2)//存在矛盾,为真币 s[s2[k]-'A']=1; else s[s2[k]-'A']=-1;//-1标识假币为light } if(s[s1[k]-'A']!=1) { if(s[s1[k]-'A']==-1) s[s1[k]-'A']=1; else s[s1[k]-'A']=2;//2标识假币为heavy } } } if(strcmp(s3,"down")==0) { for(k=0;s2[k]!=0;k++) { if(s[s2[k]-'A']!=1) { if(s[s2[k]-'A']==-1) s[s2[k]-'A']=1; else s[s2[k]-'A']=2; } if(s[s1[k]-'A']!=1) { if(s[s1[k]-'A']==2) s[s1[k]-'A']=1; else s[s1[k]-'A']=-1; } } } } for(j=0;j<20;j++) { if(s[j]==-1) { printf("%c is the counterfeit coin and it is light.\n",j+'A'); break; } if(s[j]==2) { printf("%c is the counterfeit coin and it is heavy.\n",j+'A'); break; } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator