fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define MAX_ACCOUNTS 100000
  6.  
  7. typedef struct {
  8. char account[32];
  9. int count;
  10. } Account;
  11.  
  12. int cmp(const void *a, const void *b) {
  13. return strcmp(((Account *)a)->account, ((Account *)b)->account);
  14. }
  15.  
  16. int main() {
  17. int t_Case, n;
  18. scanf("%d", &t_Case);
  19. while (t_Case--) {
  20. scanf("%d", &n);
  21. char raw_accounts[MAX_ACCOUNTS][32];
  22. for (int i = 0; i < n; ++i) {
  23. fgets(raw_accounts[i], sizeof(raw_accounts[i]), stdin);
  24. raw_accounts[i][strlen(raw_accounts[i]) - 1] = '\0';
  25. }
  26. qsort(raw_accounts, n, sizeof(raw_accounts[0]), (int (*)(const void *, const void *))strcmp);
  27. Account result[MAX_ACCOUNTS];
  28. int idx = 0, count = 1;
  29. for (int i = 1; i <= n; ++i) {
  30. if (i < n && strcmp(raw_accounts[i], raw_accounts[i - 1]) == 0) {
  31. count++;
  32. } else {
  33. strcpy(result[idx].account, raw_accounts[i - 1]);
  34. result[idx++].count = count;
  35. count = 1;
  36. }
  37. }
  38. for (int i = 0; i < idx; ++i) {
  39. printf("%s %d\n", result[i].account, result[i].count);
  40. }
  41. if (t_Case) printf("\n");
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5292KB
stdin
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
  1
03 10103538 2222 1233 6160 014 1
10103538 2222 1233 6160 0142  1

 13
  7
10103538 2222 1233 6160 0141  1
30 10103538 2222 1233 6160 014 8
5 1

 21
10103538 2222 1233 6160 0141 1
30 10103538 2222 1233 6160 01 8

 21
10103538 2222 1233 6160 014 1
30 10103538 2222 1233 6160 0 8

 21
10103538 2222 1233 6160 01 1
30 10103538 2222 1233 6160  8

 21
10103538 2222 1233 6160 0 1
30 10103538 2222 1233 6160 8