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 |
各种数据试得都对,就是WA,帮帮忙来看看程序#include <stdio.h> static int m[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0}; int c,ok,x,y; long b[5000],a[5000],l,n,q,w,an; void sort(int l,int r){ x=l;y=r+1; c=(x+y)/2; q=a[c];a[c]=a[l];a[l]=q; w=b[c];b[c]=b[l];b[l]=w; while(1){ while(a[++x]<=q); while(a[--y]>=q); if(x<y){ w=a[x];a[x]=a[y];a[y]=w; w=b[x];b[x]=b[y];b[y]=w; } else{ a[l]=a[y];a[y]=q; w=b[l];b[l]=b[y];b[y]=w; if(l==y-2){ if(a[l]>a[y-1]){ w=a[l];a[l]=a[y-1];a[y-1]=w; w=b[l];b[l]=b[y-1];b[y-1]=w; } } else if(l<y-1)sort(l,y-1); if(r==y+2){ if(a[r]<a[y+1]){ w=a[r];a[r]=a[y+1];a[y+1]=w; w=b[r];b[r]=b[y+1];b[y+1]=w; } } else if(r>y+1)sort(y+1,r); break; } } } int main(){ scanf("%d",&n);scanf("%c",&c); an=0; for(q=0;q<n;q++){ l=0; while(scanf("%c",&c)&&(c!='\n')){ if((c>='A')&&(c<='Z'))l=l*10+m[c-'A']; else if((c>='a')&&(c<='z'))l=l*10+m[c-'a']; else if((c>='0')&&(c<='9'))l=l*10+c-'0'; } for(w=0;w<an;w++){ if(a[w]==l){b[w]++;break;} } if(w==an){ a[w]=l; b[w]=1; an++; } } q=0; for(w=0;w<an;w++){ if(b[w]!=1){ a[q]=a[w]; b[q]=b[w]; q++; } } an=q; if(an==0)printf("No duplicates."); else{ if(an==2){ if(a[0]>a[1]){ q=a[1];a[1]=a[0];a[0]=q; q=b[1];b[1]=b[0];b[0]=q; } } else if(an>2){ a[an]=10000000; sort(0,an-1); } for(q=0;q<an;q++)printf("%03d-%04d %d\n",a[q]/10000,a[q]%10000,b[q]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator