#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <time.h>

#define MAX_WORD_LENGTH 100

void displayWord(char *word, int *guessed) {
    for (int i = 0; i < strlen(word); i++) {
        if (guessed[i]) {
            printf("%c ", word[i]);
        } else {
            printf("_ ");
        }
    }
    printf("\n");
}

int main() {
    setlocale(LC_ALL, "");
    srand(time(NULL));

    char *words[] = {"программирование", "компьютер", "информация", "алгоритм", "инженер","Татьяна Александровна"};
    int numWords = sizeof(words) / sizeof(words[0]);
    char word[MAX_WORD_LENGTH];
    int guessed[MAX_WORD_LENGTH] = {0};

    strcpy(word, words[rand() % numWords]);
    int wordLength = strlen(word);
    int attempts = wordLength + 5;
    int correctGuesses = 0;

    printf("Добро пожаловать в игру 'Поле Чудес'!\n");
    printf("Угадайте слово. У вас есть %d попыток.\n", attempts);

    while (attempts > 0 && correctGuesses < wordLength) {
        displayWord(word, guessed);
        printf("Введите букву: ");
        char guess;
        scanf(" %c", &guess);

        int found = 0;
        for (int i = 0; i < wordLength; i++) {
            if (word[i] == guess && !guessed[i]) {
                guessed[i] = 1;
                correctGuesses++;
                found = 1;
            }
        }

        if (found) {
            printf("Правильно!\n");
        } else {
            printf("Неправильно. Попробуйте снова.\n");
            attempts--;
        }

        printf("Осталось попыток: %d\n", attempts);
    }

    if (correctGuesses == wordLength) {
        printf("Поздравляем! Вы угадали слово: %s\n", word);
    } else {
        printf("К сожалению, вы не угадали слово. Это было: %s\n", word);
    }

    return 0;
}