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 |
我用这样试了,还是超时啊!郁闷中...........源程序如下:In Reply To:Re:这样怎么还不对啊?总草时,谁能帮我解决一下? Posted by:gz2001 at 2003-07-08 11:20:30 #include <iostream> using namespace std; int cmp(const void *t1,const void *t2) {int *a,*b; a=(int *)t1; b=(int *)t2; if (*a>*b) return 1; if (*a<*b) return -1; return 0; } void main() { int a[100000]; char b[50]; int num; cin>>num; if (num<2) { cin>>b; cout<<"No duplicates."; } else { for (int i=0;i<num;i++) { cin>>b; int p1=0; int result=0; for (int j=0;j<strlen(b);j++) { char tmp=b[j]; switch(tmp) { case('A'): case('B'): case('C'): { b[j]='2'; break; } case('D'): case('E'): case('F'): { b[j]='3'; break; } case('G'): case('H'): case('I'): { b[j]='4'; break; } case('J'): case('K'): case('L'): { b[j]='5'; break; } case('M'): case('N'): case('O'): { b[j]='6'; break; } case('P'): case('R'): case('S'): { b[j]='7'; break; } case('T'): case('U'): case('V'): { b[j]='8'; break; } case('W'): case('X'): case('Y'): { b[j]='9'; break; } case(' '): { b[j]='.'; break; } } if (b[j]>='0' && b[j]<='9') { b[p1++]=b[j]; result=10*result+b[j]-('1'-1); } } a[i]=result; } qsort(a,num,sizeof(int),cmp); int flag=0; int pp=0; while(pp<num) { int sum=1; int i=1; while(a[pp]==a[pp+i]) { i++; sum++; } if (sum>1) { int x1=a[pp]/10000; int y1=a[pp] % 10000; if (x1>99) cout<<x1<<"-"; else if (x1>9) cout<<"0"<<x1<<"-"; else cout<<"00"<<x1<<"-"; //cout<<"-"; if (y1>999) cout<<y1<<" "<<sum<<endl; else if (y1>99) cout<<"0"<<y1<<" "<<sum<<endl; else if (y1>9) cout<<"00"<<y1<<" "<<sum<<endl; else if (y1>=0) cout<<"000"<<y1<<" "<<sum<<endl; flag=1; // cout<<" "<<sum<<endl; } pp=pp+i; } if (flag==0) cout<<"No duplicates."; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator