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 |
WA,帮找错吧!3Q!#include <stdio.h> #include <string.h> const char con[]={"ABCDEFGHIJKL"}; int flag[12]; void compare(char s1[],char s2[],char s3[]) { int length; int i; length=strlen(s1); if(strcmp(s3,"even")==0) { for(i=0;i<length;i++) { flag[s1[i]-65]=0; flag[s2[i]-65]=0; } } else if(strcmp(s3,"up")==0) { for(i=0;i<length;i++) { if(flag[s1[i]-65]==-13) { flag[s1[i]-65]=1; } else if(flag[s1[i]-65]>0) { flag[s1[i]-65]=0; } else if(flag[s1[i]-65]<0) { flag[s1[i]-65]--; } if(flag[s2[i]-65]==-13) { flag[s2[i]-65]=1; } else if(flag[s2[i]-65]>0) { flag[s2[i]-65]=0; } else if(flag[s2[i]-65]<0) { flag[s2[i]-65]--; } } } else { for(i=0;i<length;i++) { if(flag[s1[i]-65]==-13) { flag[s1[i]-65]=-1; } else if(flag[s1[i]-65]<0) { flag[s1[i]-65]=0; } else if(flag[s1[i]-65]>0) flag[s1[i]-65]++; if(flag[s2[i]-65]==-13) { flag[s2[i]-65]=-1; } else if(flag[s2[i]-65]<0) { flag[s2[i]-65]=0; } else if(flag[s2[i]-65]>0) flag[s2[i]-65]++; } } } int main() { int i,m,j,k,j1,k1; char s1[7],s2[7],s3[5]; scanf("%d",&m); while(m>0) { m--; for(i=0;i<12;i++) flag[i]=-13; for(i=0;i<3;i++) { scanf("%s %s %s",s1,s2,s3); compare(s1,s2,s3); } for(i=0;i<12;i++) { j=0;k=0; if(j>flag[i]&&flag[i]!=-13) { j=flag[i]; j1=i; } if(flag[i]>k&&flag[i]!=-13) { k=flag[i]; k1=i; } } if(j<0) printf("%c is the counterfeit coin and it is light.\n",con[j1]); if(k1>0) printf("%c is the counterfeit coin and it is heavy.\n",con[k1]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator