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 |
好长的代码啊In Reply To:自己用TC都调试通过了,可为什么老是WA呢?实在搞不明白,高手帮帮测试一下吧。不慎感激~~~ Posted by:zhangcy at 2005-07-06 10:58:02 Source Problem Id:1002 User Id:xfxyjwf Memory:412K Time:249MS Language:C++ Result:Accepted Source #include <stdio.h> #include <stdlib.h> int d[26] = { 2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9 }; int *a; int n; int cmpA(const void *a,const void *b) { return *(const int *)a-*(const int *)b; } int main () { int i,j; bool haveDuplicates; char x[100]; scanf("%d",&n); a=new int[n+1]; scanf("\n"); for(j=1;j<=n;j++) { gets(x); a[j]=0; for(i=0;x[i]!='\0';i++) { if(x[i]>='A' && x[i]<='Z') { a[j]=a[j]*10+d[x[i]-'A']; continue; } if(x[i]>='0' && x[i]<='9') { a[j]=a[j]*10+x[i]-'0'; continue; } } } haveDuplicates=false; qsort(&a[1],n,sizeof(a[1]),cmpA); j=1; for(i=2;i<=n;i++) { if(a[i]==a[i-1]) j++; else { if(j>1) { haveDuplicates=true; printf("%03d-%04d %d\n",a[i-1]/10000,a[i-1]%10000,j); j=1; } } } if(j>1) printf("%03d-%04d %d\n",a[n]/10000,a[n]%10000,j); else if(!haveDuplicates) printf("No duplicates.\n"); delete []a; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator