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 |
老是超时。。各位帮我改改。。谢了#include"stdio.h" #include"string.h" tran(char ch[],char a[],char b[]) { char str[30]; int i,j=0,r,len,lena,lenb; len=strlen(ch); lena=strlen(a); lenb=strlen(b); for(i=0;i<len;i++) { if(ch[i]=='-') continue; if(j==3) str[j++]='-'; for(r=0;r<lena;r++) if(ch[i]==a[r]) break; str[j++]=b[r]; } str[j]='\0'; strcpy(ch,str); } void main() { long int n,i,t,j=0,r,s=0,k=0,p=0,time[10001]; char st[20],str[10001][20],ch[20],a[]="01ABC2DEF3GHI4JKL5MNO6PRS7TUV8WXY9",b[]="0122223333444455556666777788889999"; scanf("%d",&n); for(i=0;i<n;i++) { r=1; t=1; scanf("%s",st); tran(st,a,b); while(r<=s) { t=strcmp(st,str[r]); if(t!=0) r++; else break; } if(r>s) { strcpy(str[++s],st); time[s]=1; } else time[r]++; } strcpy(str[s+1],"zzzzzzzzzzzzzzzzzzz"); time[s+1]=2; for(i=1;i<=s;i++) { if(time[i]==1) { p++; continue; } strcpy(ch,str[i]); for(j=i+1;j<=s+1;j++) { if(time[j]==1) continue; t=strcmp(str[i],str[j]); if(t>0) { t=0; strcpy(st,str[i]); strcpy(str[i],str[j]); strcpy(str[j],st); k=time[i]; time[i]=time[j]; time[j]=k; } } if(p!=s) printf("%s %d\n",str[i],time[i]); } if(p==s) 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