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啊?能测试的数据都过了啊?????请各位大虾指教,用c++做的#include <iostream> #include <algorithm> using namespace std; int comp(const void *p1,const void *p2) { return *((int*)p2)>*((int*)p1)?-1:1; } int main() { int M=50; int size=7; int i,j,k,l,w,si,d; char p[200],b[200][10],a[200][10]; bool s[200]; for(i=0;i<size;i++) s[i]=0; cin>>d; for(j=0;j<d;j++) { w=0; for(i=0;i<M;i++) p[i]=0; cin >> p; si = strlen(p); for (i=0; i<si; i++) { if(p[i]!='-') {b[j][w]=p[i];w++;} } for(i=0;i<size;i++) { switch(b[j][i]) { case 'A':case 'B':case 'C':b[j][i]=2+'0';break; case 'D':case 'E':case 'F':b[j][i]=3+'0';break; case 'G':case 'H':case 'I':b[j][i]=4+'0';break; case 'J':case 'K':case 'L':b[j][i]=5+'0';break; case 'M':case 'N':case 'O':b[j][i]=6+'0';break; case 'P':case 'R':case 'S':b[j][i]=7+'0';break; case 'T':case 'U':case 'V':b[j][i]=8+'0';break; case 'W':case 'X':case 'Y':b[j][i]=9+'0';break; default:break; } } } if(d!=1) { int z=0; for(j=0;j<d-1;j++) { for(k=j+1;k<d;k++) { int count=0; if(!s[k]) { for(i=0;i<size;i++) { if(b[j][i]==b[k][i]) count++; } if(count==size) { if(!s[j]) { z++; for(l=0;l<size;l++) a[z][l]=b[j][l]; } s[k]=1;s[j]=1; } } } } if(z!=0) { int c[200],f[200]; for(i=0;i<z;i++) {c[i]=0;f[i]=0;} for(i=1;i<=z;i++) { for(j=0;j<d;j++) { int st=0; for(k=0;k<size;k++) { if(b[j][k]==a[i][k]) st++; } if(st==size) c[i-1]++; } } for(i=1;i<=z;i++) f[i-1]=(a[i][0]-'0')*1000000+(a[i][1]-'0')*100000+(a[i][2]-'0')*10000+(a[i][3]-'0')*1000+(a[i][4]-'0')*100+(a[i][5]-'0')*10+a[i][6]-'0'; qsort(f,z,sizeof(int),comp); for(i=0;i<size;i++) s[i]=0; for(i=0;i<z;i++) { for(k=1;k<=z;k++) { if(!s[k]) { if((a[k][0]-'0')*1000000+(a[k][1]-'0')*100000+(a[k][2]-'0')*10000+(a[k][3]-'0')*1000+(a[k][4]-'0')*100+(a[k][5]-'0')*10+a[k][6]-'0'==f[i]) { for(j=0;j<3;j++) cout<<a[k][j]; cout<<"-"; for(j=3;j<size;j++) cout<<a[k][j]; cout<<" "<<c[k-1]; cout<<endl; s[k]=1; } } } } } else cout<<"No duplicates."<<endl; } else cout<<"No duplicates."<<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