Advertisement
STANAANDREY

cnt fr str c

Dec 19th, 2022 (edited)
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #define MOD (int)1e9 + 7
  6. #define PRIME 31
  7. #define NMAX 10
  8. #define NAME_MAX_LEN 30
  9. char s[NMAX][NAME_MAX_LEN], dist[NMAX][NAME_MAX_LEN];
  10. int freq[NMAX];
  11.  
  12. int main() {
  13.   int n;
  14.   scanf("%d", &n);
  15.   for (int i = 0; i < n; i++) {
  16.     scanf("%s", s[i]);
  17.   }
  18.  
  19.   int distSz = 0;
  20.   for (int i = 0; i < n; i++) {
  21.     int pos = -1;
  22.     for (int j = 0; j < distSz && pos == -1; j++) {
  23.       if (!strcmp(dist[j], s[i])) {
  24.     pos = j;
  25.       }
  26.     }
  27.  
  28.     if (pos == -1) {
  29.       freq[distSz] = 1;
  30.       strcpy(dist[distSz++], s[i]);
  31.     } else {
  32.       freq[pos]++;
  33.     }
  34.   }
  35.  
  36.   for (int j = 0; j < distSz; j++) {
  37.     printf("%s: %d\n", dist[j], freq[j]);
  38.   }
  39.   return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement