Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. bool is_equal(char *a, char *b) {
  7.     int c = strlen(a);
  8.     for (int i = 0; i <= c; i++)
  9.         if (a[i] != b[i])
  10.             return false;
  11.     return true;
  12. }
  13.  
  14. int main(void) {
  15.     char d[30][11];
  16.     int n = 0;
  17.     printf("Enter the string:\n");
  18.     while (1) {
  19.         char c;
  20.         int i = 0;
  21.         while (1) {
  22.             c = getchar();
  23.             if (c == ',' || c == '.') {
  24.                d[n][i] = '\0';
  25.                 break;
  26.             }
  27.             d[n][i] = c;
  28.             i++;
  29.         }
  30.         if (c == '.')
  31.             break;
  32.  
  33.     }
  34.     printf("Words and their number:\n");
  35.     for (int i = 0; i <= n; i++) {
  36.         bool flag = true;
  37.         int cnt = 0;
  38.         for (int j = 0; j <= n; j++) {
  39.             if (is_equal(d[i], d[j])) {
  40.                 if (i < j) {
  41.                     flag = false;
  42.                     break;
  43.                 }
  44.                 cnt++;
  45.             }
  46.         }
  47.         if (flag)
  48.             printf("%s %d\n", d[i], cnt);
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement