
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define MAX_WORDS 1000
#define MAX_WORD_LEN 100

typedef struct {
    char word[MAX_WORD_LEN];
    int count;
} WordCount;

int find_word(WordCount words[], int word_count, const char *word) {
    for (int i = 0; i < word_count; i++) {
        if (strcmp(words[i].word, word) == 0) {
            return i;
        }
    }
    return -1;
}

int main() {
    char text[10000];
    WordCount words[MAX_WORDS];
    int word_count = 0;

    printf("Введіть текст:\n");
    fgets(text, sizeof(text), stdin);

    char *token = strtok(text, " \t\n\r");
    while (token != NULL) {
        int index = find_word(words, word_count, token);
        if (index >= 0) {
            words[index].count++;
        } else {
            strcpy(words[word_count].word, token);
            words[word_count].count = 1;
            word_count++;
        }
        token = strtok(NULL, " \t\n\r");
    }

    printf("\nЧастота слів:\n");
    for (int i = 0; i < word_count; i++) {
        printf("%s: %d\n", words[i].word, words[i].count);
    }

    return 0;
}
