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 |
麻烦大牛帮我看看为什么会TLE?那些地方要改进?谢谢!#include<stdio.h> #include<string> #include<stdlib.h> int cmp(const void *a,const void *b) { char *aa=*(char **)a; char *bb=*(char **)b; return strcmp(aa,bb); } int main() { int n,len; scanf("%d",&n); int i,j,k; int count=1; int f; char **a; char **b; a = new char*[n]; b = new char*[n]; int *flag = new int[n]; for(i=0;i<n;i++) { a[i] = new char[20]; b[i] = new char[7]; flag[i]=0; } for(i=0;i<n;i++) { scanf("%s",a[i]); } for(i=0;i<n;i++) { k=0; len=strlen(a[i]); for(j=0;j<len;j++) { if(a[i][j]>='0' && a[i][j]<='9') { b[i][k] = a[i][j]; k++; } else if(a[i][j]>='A' && a[i][j]<='Z') { switch(a[i][j]) { case 'A':b[i][k]='2';k++;break; case 'B':b[i][k]='2';k++;break; case 'C':b[i][k]='2';k++;break; case 'D':b[i][k]='3';k++;break; case 'E':b[i][k]='3';k++;break; case 'F':b[i][k]='3';k++;break; case 'G':b[i][k]='4';k++;break; case 'H':b[i][k]='4';k++;break; case 'I':b[i][k]='4';k++;break; case 'J':b[i][k]='5';k++;break; case 'K':b[i][k]='5';k++;break; case 'L':b[i][k]='5';k++;break; case 'M':b[i][k]='6';k++;break; case 'N':b[i][k]='6';k++;break; case 'O':b[i][k]='6';k++;break; case 'P':b[i][k]='7';k++;break; case 'R':b[i][k]='7';k++;break; case 'S':b[i][k]='7';k++;break; case 'T':b[i][k]='8';k++;break; case 'U':b[i][k]='8';k++;break; case 'V':b[i][k]='8';k++;break; case 'W':b[i][k]='9';k++;break; case 'X':b[i][k]='9';k++;break; case 'Y':b[i][k]='9';k++;break; } } } b[i][k]='\0'; } qsort(b,n,sizeof(char*),cmp); f=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(strcmp(b[j],b[i])==0 && flag[j]==0) { count++; flag[j]=1; } } if(count>1) { printf("%c%c%c-%c%c%c%c %d\n",b[i][0],b[i][1],b[i][2],b[i][3],b[i][4],b[i][5],b[i][6],count); count=1; f=1; } } if(f==0) printf("No duplicates.\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator