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,能帮忙看一下吗?#include<iostream> using namespace std; int main() { int m; char left[3][6],right[3][6],result[3][4],b[12]={'A','B','C','D','E','F','G','H','I','J','K','L'}; int a[12]; char heavy[12],light[12]; int x=0,y=0; int i,j,k; cin>>m; while(m--) { x=y=0; for(i=0;i<12;i++) a[i]=0; for(i=0;i<3;i++) { cin>>left[i]>>right[i]>>result[i]; if(strcmp(result[i],"even")==0) { for(j=0;j<strlen(left[i]);j++) { a[left[i][j]-65]=1; a[right[i][j]-65]=1; } } else if(strcmp(result[i],"up")==0) { for(j=0;j<12;j++) { for(k=0;k<strlen(left[i]);k++) if(b[j]==left[i][k]||b[j]==right[i][k]) break; if(k>=strlen(left[i])) a[j]=1; } for(k=0;k<strlen(left[i]);k++) { heavy[x++]=left[i][k]; light[y++]=right[i][k]; } } else if(strcmp(result[i],"down")==0) { for(j=0;j<12;j++) { for(k=0;k<strlen(left[i]);k++) if(b[j]==left[i][k]||b[j]==right[i][k]) break; if(k>=strlen(left[i])) a[j]=1; } for(k=0;k<strlen(left[i]);k++) { heavy[x++]=right[i][k]; light[y++]=left[i][k]; } } } k=0; for(j=0;j<x;j++) { for(k=0;k<y;k++) if(heavy[j]==light[k]) a[light[k]-65]=1; } for(j=0;j<12;j++) if(a[j]!=1) break; for(i=0;i<x;i++) if(heavy[i]==b[j]) break; if(i<x) cout<<b[j]<<" is the counterfeit coin and it is heavy."<<endl; else { for(i=0;i<y;i++) if(light[i]==b[j]) break; cout<<b[j]<<" is the counterfeit coin and it is light."<<endl; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator