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 |
Re:还是超时!!崩溃!!In Reply To:不要用n^2的算法 Posted by:Assassin_cpy at 2008-11-03 12:54:05 #include<stdio.h> #include<stdlib.h> #include<string.h> int cmp(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main() { int n,i,j,k,p,c,b,K; char d[25]="ABCDEFGHIJKLMNOPRSTUVWXY"; int D[25]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9}; while(scanf("%d",&n)!=EOF) { char a[n+1][20]; int A[n+1],B[n+1][2]; for(i=0;i<n;i++) { scanf("%s",a[i]); b=strlen(a[i]); c=1000000,A[i]=0; for(j=0;j<=b-1;j++) { if(a[i][j]>='0'&&a[i][j]<='9') A[i]=A[i]+((a[i][j]-'0')*c),c=c/10; else if(a[i][j]>='A'&&a[i][j]<='C') A[i]=A[i]+(2*c),c=c/10; else if(a[i][j]>='D'&&a[i][j]<='F') A[i]=A[i]+(3*c),c=c/10; else if(a[i][j]>='G'&&a[i][j]<='I') A[i]=A[i]+(4*c),c=c/10; else if(a[i][j]>='J'&&a[i][j]<='L') A[i]=A[i]+(5*c),c=c/10; else if(a[i][j]>='M'&&a[i][j]<='O') A[i]=A[i]+(6*c),c=c/10; else if(a[i][j]>='P'&&a[i][j]<='S') A[i]=A[i]+(7*c),c=c/10; else if(a[i][j]>='T'&&a[i][j]<='V') A[i]=A[i]+(8*c),c=c/10; else if(a[i][j]>='W'&&a[i][j]<='Y') A[i]=A[i]+(9*c),c=c/10; } } c=0,k=0,K=0; for(i=0;i<n-1;i++) { if(A[i]!=12345678) { b=1; for(j=i+1;j<n;j++) if(A[i]==A[j]) b++,A[j]=12345678; if(b>1) B[c][0]=A[i],B[c][1]=b,c++; } } if(c==0) {printf("No duplicates.\n");} else { qsort(B,c,sizeof(B[0]),cmp); for(i=0;i<c;i++) { n=B[i][0]/10000,B[i][0]=B[i][0]%10000; if(n>=100) {printf("%d-",n);} else if(n>=10&&n<=99) {printf("0%d-",n);} else {printf("00%d-",n);} if(B[i][0]>=1000) {printf("%d ",B[i][0]);printf("%d\n",B[i][1]);} else if(B[i][0]>=100&&B[i][0]<=999) {printf("0%d ",B[i][0]);printf("%d\n",B[i][1]);} else if(B[i][0]>=10&&B[i][0]<=99) {printf("00%d ",B[i][0]);printf("%d\n",B[i][1]);} else {printf("000%d ",B[i][0]);printf("%d\n",B[i][1]);} } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator