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 |
向dalao们求助,总是TLE,求救#include<stdio.h> #include<string.h> #define N 100000 #define M 300 char a[N][M],r[N][M]; int counter[N],counter_a[N]={0}; void sort(char a[][M],int n); int main() { int n,i,j,len,count,t=0,time=0,t1=0; scanf("%d",&n); for(i=0;i<n;i++) { counter[i]=1; } while(getchar()!='\n'); for(i=0;i<n;i++) { gets(a[i]); } for(i=0;i<n;i++) { count=0; len=strlen(a[i]); for(j=0;j<len;j++) { if(a[i][j]!='-'&&a[i][j]!='Q'&&a[i][j]!='Z') { if(count==3) { r[i][count]='-'; count++; } if(a[i][j]>='0'&&a[i][j]<='9')r[i][count]=a[i][j]; else { switch(a[i][j]) { case 'A':r[i][count]='2'; break; case 'B':r[i][count]='2'; break; case 'C':r[i][count]='2'; break; case 'D':r[i][count]='3'; break; case 'E':r[i][count]='3'; break; case 'F':r[i][count]='3'; break; case 'G':r[i][count]='4'; break; case 'H':r[i][count]='4'; break; case 'I':r[i][count]='4'; break; case 'J':r[i][count]='5'; break; case 'K':r[i][count]='5'; break; case 'L':r[i][count]='5'; break; case 'M':r[i][count]='6'; break; case 'N':r[i][count]='6'; break; case 'O':r[i][count]='6'; break; case 'P':r[i][count]='7'; break; case 'R':r[i][count]='7'; break; case 'S':r[i][count]='7'; break; case 'T':r[i][count]='8'; break; case 'U':r[i][count]='8'; break; case 'V':r[i][count]='8'; break; case 'W':r[i][count]='9'; break; case 'X':r[i][count]='9'; break; case 'Y':r[i][count]='9'; break; } } /* else if(a[i][j]=='A'||a[i][j]=='B'||a[i][j]=='C')r[i][count]='2'; else if(a[i][j]=='D'||a[i][j]=='E'||a[i][j]=='F')r[i][count]='3'; else if(a[i][j]=='G'||a[i][j]=='H'||a[i][j]=='I')r[i][count]='4'; else if(a[i][j]=='J'||a[i][j]=='K'||a[i][j]=='L')r[i][count]='5'; else if(a[i][j]=='M'||a[i][j]=='N'||a[i][j]=='O')r[i][count]='6'; else if(a[i][j]=='P'||a[i][j]=='R'||a[i][j]=='S')r[i][count]='7'; else if(a[i][j]=='T'||a[i][j]=='U'||a[i][j]=='V')r[i][count]='8'; else if(a[i][j]=='W'||a[i][j]=='X'||a[i][j]=='Y')r[i][count]='9'; */ count++; } } } sort(r,n); for(i=1;i<n;i++) { if(strcmp(r[i],r[i-1])==0) { counter[t]++; counter_a[t]=i; if(strcmp(r[i],r[i+1])!=0)t++; } } for(i=0;i<=t;i++) { if(counter[i]==1)continue; printf("%s %d\n",r[counter_a[i]],counter[i]); } for(i=0;i<=t;i++) { if(counter[i]==1)time++; if(time==t+1)printf("No duplicates.\n"); } return 0; } void sort(char a[][M],int n) { int i,j,k; char ch[M]; for(i=0;i<n-1;i++) { k=i; for(j=i+1;j<n;j++) { if(strcmp(a[k],a[j])>0)k=j; } if(k!=i) { strcpy(ch,a[k]); strcpy(a[k],a[i]); strcpy(a[i],ch); } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator