fork(5) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int myCompare (const void * a, const void * b ) {
  5. const char *pa = (const char*)a;
  6. const char *pb = (const char*)b;
  7.  
  8. return strcmp(pa,pb);
  9. }
  10. int cmp(const void * a, const void * b)
  11. {
  12. return strcmp(a,b);
  13. }
  14. int main(int argc, const char * argv[])
  15. {
  16. int t;scanf("%d",&t);
  17. char a[100000][34];
  18. char temp[34];
  19. char c;int n,i,j,k;
  20. while(t--){
  21. scanf("%d",&n);scanf("%c",&c);
  22. for(i=0;i<n;i++){gets(a[i]);}
  23. qsort(a, n, sizeof(a[0]), cmp);
  24. i=0;
  25. while(i<n){
  26. j=i+1;k=1;strcpy(temp,a[i]);
  27. while(strcmp(temp,a[j])==0){
  28. k++;j++;
  29. }
  30. i=j;
  31. printf("%s %d\n",a[j-1],k);
  32. }
  33. printf("\n");
  34. }
  35.  
  36. return 0;
  37.  
  38. }
  39.  
Success #stdin #stdout 0s 5496KB
stdin
2
6
03 10103538 2222 1233 6160 0142 
03 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0142 
30 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0142 

5
30 10103538 2222 1233 6160 0144 
30 10103538 2222 1233 6160 0142 
30 10103538 2222 1233 6160 0145 
30 10103538 2222 1233 6160 0146 
30 10103538 2222 1233 6160 0143 
stdout
03 10103538 2222 1233 6160 0141  1
03 10103538 2222 1233 6160 0142  1
30 10103538 2222 1233 6160 0141  2
30 10103538 2222 1233 6160 0142  2

30 10103538 2222 1233 6160 0142  1
30 10103538 2222 1233 6160 0143  1
30 10103538 2222 1233 6160 0144  1
30 10103538 2222 1233 6160 0145  1
30 10103538 2222 1233 6160 0146  1