http://poj.org/problem?id=2945
字符串,可以用字典树,我用qsort做的~
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 5 char s[20010][23]; 6 int n, m; 7 8 int cmp(const void *a, const void *b) 9 { 10 return strcmp((char *)a, (char *)b); 11 } 12 13 int main() 14 { 15 int i, sum[20010], count[20010]; 16 while(scanf("%d%d%*c", &n, &m), n||m) 17 { 18 for(i=0; i<n; i++) 19 { 20 scanf("%s", s[i]); 21 s[i][m] = '\0'; 22 } 23 qsort(s, n, sizeof(s[0]), cmp); 24 memset(sum, 0, sizeof(sum)); 25 count[0] = 1; 26 for(i=1; i<n; i++) 27 { 28 if(strcmp(s[i], s[i-1]) == 0) 29 { 30 count[i] = count[i-1]+1; 31 } 32 else 33 { 34 sum[count[i-1]] ++; 35 //printf("%d %d\n", i-1, count[i-1]); 36 count[i] = 1; 37 } 38 } 39 sum[count[n-1]] ++; 40 for(i=1; i<=n; i++) 41 { 42 printf("%d\n", sum[i]); 43 } 44 } 45 return 0; 46 }