uva755 - 487--3279
哎,这两天做那道题都FAIL,真是郁闷,强烈的打击了我的积极性,终于有一道AC了,花了一早晨的时间,只是这道题出错的地方实在是太离谱,真是不应该啊,同一个地方又摔倒了一次
View Code
#include<stdio.h> #include<string.h> #include<stdlib.h> int b[]={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[100010]; int cmp(const void *a,const void *b) { return (*(int *)a-*(int *)b); }; int main() { char st[1000]; int T; scanf("%d",&T); int N, i, j, k, flag = 1, s; scanf("%d",&N); getchar(); for(i = 0;i < N; i++) { s = 0; gets(st); for(j = 0; st[j] != '\0'; j++) { if(st[j] >= '0' && st[j] <= '9') s = s*10 + st[j]-'0'; else if(st[j] >= 'A' && st[j] < 'Z' && st[j] != 'Q') s = s*10 + b[st[j]-'A']; } a[i] = s; } qsort(a,N,sizeof(a[0]),cmp); for(i = 0;i <= N-1; ) { k = 1; for(j = i+1;j < N; j++) { if(a[j] == a[i]) k++; else break; } if(k > 1) { printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,k); flag = 0; } i = j; } if(flag) printf("No duplicates.\n"); return 0; }