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> 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]=100; flag[s2[i]-65]=100; } } else if(strcmp(s3,"up")==0) { for(i=0;i<length;i++) { if(flag[s1[i]-65]==0) { flag[s1[i]-65]--; } else if(flag[s1[i]-65]>0&&flag[s1[i]-65]!=100) { flag[s1[i]-65]=100; } else if(flag[s1[i]-65]<0) { flag[s1[i]-65]--; } if(flag[s2[i]-65]==0) { flag[s2[i]-65]++; } else if(flag[s2[i]-65]<0) { flag[s2[i]-65]=100; } else if(flag[s2[i]-65]>0&&flag[s2[i]-65]!=100) { flag[s2[i]-65]++; } } } else { for(i=0;i<length;i++) { if(flag[s1[i]-65]==0) { flag[s1[i]-65]++; } else if(flag[s1[i]-65]<0) { flag[s1[i]-65]=100; } else if(flag[s1[i]-65]>0&&flag[s1[i]]!=100) flag[s1[i]-65]++; if(flag[s2[i]-65]==0) { flag[s2[i]-65]--; } else if(flag[s2[i]-65]>0&&flag[s1[i]]!=100) { flag[s2[i]-65]=100; } 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]=0; for(i=0;i<3;i++) { scanf("%s %s %s",s1,s2,s3); compare(s1,s2,s3); } j=0;k=0; for(i=0;i<12;i++) { if(j<flag[i]&&flag[i]!=100) { j=flag[i]; j1=i; } if(flag[i]<k) { k=flag[i]; k1=i; } } if(j>0) printf("%c is the counterfeit coin and it is heavy.\n",con[j1]); if(k<0) printf("%c is the counterfeit coin and it is light.\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