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 |
bubblesort-_-In Reply To:已经用数字存储排序了,还是超时,谁给我看看 Posted by:donge at 2005-09-22 13:17:27 > #include <stdio.h> > > #include <string.h> > > int pw(int k){ > int pow=1; > for(int i=0;i<6-k;i++) > pow*=10; > return pow; > } > int lib[100000]; > int lnum[100000]; > int x=0; > void bubblesort() > { > int ii,jj,temp,tag; > > for(ii=0,tag=1;tag==1&&ii<x-1;ii++){ > tag=0; > for(jj=0;jj<x-ii-1;jj++) > if(lib[jj]>lib[jj+1]){ > temp=lib[jj];lib[jj]=lib[jj+1];lib[jj+1]=temp; > temp=lnum[jj];lnum[jj]=lnum[jj+1];lnum[jj+1]=temp; > tag=1; > } > } > } > > int main() > { > int n; > int i,j,k,len; > char s[18]; > char t[18]; > int num=0; > > int dp=0; > > int ok=0; > > scanf("%d",&n); > > for(i=0;i<n;i++) > { > lnum[i]=0; > lib[i]=-1; > } > > for(i=0;i<n;i++) > { > num=0; > scanf("%s",&s); > len=strlen(s); > > for(j=0,k=0;j<len;j++) > { > switch(s[j]) > { > case '0' ... '9' : > num+=(s[j]-'0')*pw(k); > k++; > break; > case '-':continue; > case 'A' ... 'C': > num+=2*pw(k); > k++; > break; > case 'D' ... 'F': > num+=3*pw(k); > k++; > break; > case 'G' ... 'I': > num+=4*pw(k); > k++; > break; > case 'J' ... 'L': > num+=5*pw(k); > k++; > break; > case 'M' ... 'O': > num+=6*pw(k); > k++; > break; > case 'P' ... 'S': > num+=7*pw(k); > k++; > break; > case 'T' ... 'V': > num+=8*pw(k); > k++; > break; > case 'W' ... 'Y': > num+=9*pw(k); > k++; > break; > } > > } > > ok=0; > for(j=0;j<x+1;j++) > { > if(lib[j]==num){ > ok=1;lnum[j]++;dp=1;break; > > } > } > if(ok==0){ > lib[x]=num; > lnum[x]++; > x++; > } > } > > bubblesort(); > > if(dp==1)for(i=0;i<x;i++) > { > if(lnum[i]>1) > printf("%03d-%04d %d\n",lib[i]/10000,lib[i]%10000,lnum[i]); > } > else 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