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 <stdlib.h> #include <string.h> #define maxn 10 int map[] = {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 cp(const void *a,const void *b) { return(*(long*)a>*(long*)b?1:-1); } void main() {char b[100]; long a[maxn],i,j,l,num,ok=0,n=-1,c; scanf("%ld",&num); for (n=0;n<num;n++) { scanf("%s",b); l=strlen(b); j=-1; for (i=0; i<l;i++) if ((b[i]>='0')&&(b[i]<='9')) {j++; b[j]=b[i];} else if ((b[i]>='A')&&(b[i]<='Z')) {j++; b[j]='0'+map[b[i]-'A'];} b[7]='\0'; a[n]=atol(b); } a[num]=10000000; qsort(a,num,sizeof(a[0]),cp); j=0; ok=0; for (i=0; i<num;) {c=1; for (j=i+1; a[i]==a[j]&&j<num;j++) c++; if (c>1) {printf("%.3ld-%.4ld %ld\n",a[i]/10000,a[i]%10000,j-i); ok=1;} i=j; } if (!ok) 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