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> #include<ctype.h> int test(char* A,char *B,char *C,int sign,int x); int main(void) { int n,i,sign=0; char A[3][10],B[3][10],C[3][10];//A B C 分别记录天平左侧、右侧的硬币,天平平衡状况 scanf("%d",&n); for(i=0;i<n;i++) { int j; for(j=0;j<3;j++) { scanf("%s",A[j]); scanf("%s",B[j]); scanf("%s",C[j]); } for(j=0;j<12;j++)//假设假币偏轻、枚举 { int k; for(k=0;k<3;k++) { if(test(A[k],B[k],C[k],sign,j)==0) break; } if(k==3) break; } if(j!=12) printf("%c is the counterfeit coin and it is light. \n",j+65); else { sign=1; for(j=0;j<12;j++)//假设假币偏重,枚举 { int k; for(k=0;k<3;k++) { if(test(A[k],B[k],C[k],sign,j)==0) break; } if(k==3) break; } if(j!=12) printf("%c is the counterfeit coin and it is heavy. \n",j+65); } } } int test(char* A,char *B,char *C,int sign,int x)//验证枚举结果是否正确的函数,正确返回1 { int i=0; int a,b; a=b=0; while(A[i]!='\0') { if(A[i]-65==x) a+=sign? 2:0;//假设真币重是1,假币偏轻重为0,偏重为2 else a+=1; i++; } i=0; while(B[i]!='\0') { if(B[i]-65==x) b+=sign? 2:0; else b+=1; i++; } if((a-b>0 && C[0]== 'u') || (a-b==0 && C[0] == 'e') || (a-b<0 && C[0] == 'd')) return 1; else return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator