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 |
不知道为什么超时,麻烦大家有空的时候帮看下!先谢谢各位了!//------------1002 487-3279 #include<stdio.h> #include<string.h> void QuickSort(int used[][2],int p,int r) { int x,i,j,temp,q; if (p<r) { x=used[r][0]; i=p-1; for (j=p;j<=r-1;j++) if (used[j][0]<=x) { i++; temp=used[i][0]; used[i][0]=used[j][0]; used[j][0]=temp; temp=used[i][1]; used[i][1]=used[j][1]; used[j][1]=temp; } temp=used[i+1][0]; used[i+1][0]=used[r][0]; used[r][0]=temp; temp=used[i+1][1]; used[i+1][1]=used[r][1]; used[r][1]=temp; q=i+1; QuickSort(used,p,q-1); QuickSort(used,q+1,r); } } int main(void) { int n; int used[100001][2]; int total,i,j,k,number,l,count,newNum,multiply,numZero,start,duplicates; char read[100],out[100]; scanf("%d",&n); total=0; for (i=1;i<=n;i++) { used[i][0]=0; used[i][1]=0; } for (i=1;i<=n;i++) { scanf("%s",read); l=strlen(read); number=0; k=1000000; multiply=0; count=7; // count digits. numZero=0; for (j=0;j<=l-1;j++) { if (read[j]=='0' && start==0) numZero++; else start=1; if (read[j]=='-') continue; if ('0'<=read[j] && read[j]<='9') multiply=read[j]-'0'; else { if ('A'<=read[j] && read[j]<='O') multiply=2+(read[j]-'A')/3; else { if (read[j]=='P' || read[j]=='R' || read[j]=='S') multiply=7; else { if (read[j]=='T' || read[j]=='U' || read[j]=='V') multiply=8; else { if (read[j]=='W' || read[j]=='X' || read[j]=='Y') multiply=9; } } } } number+=multiply*k; k/=10; } newNum=1; for (j=1;j<=total;j++) if (used[j][0]==number) { used[j][1]++; newNum=0; break; } if (newNum==1) { total++; used[total][0]=number; used[total][1]++; } } QuickSort(used,1,total); duplicates=0; for (i=1;i<=total;i++) if (used[i][1]>1) { itoa(used[i][0],out,10); l=strlen(out); for (j=l-1;j>=0;j--) out[j+7-l]=out[j]; for (j=0;j<=6-l;j++) out[j]='0'; for (j=0;j<=2;j++) printf("%c",out[j]); printf("-"); for (j=3;j<=6;j++) printf("%c",out[j]); printf(" %d\n",used[i][1]); duplicates=1; } if (duplicates==0) printf("No duplicates.\n"); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator