UVA - 489 Hangman Judge 【模拟】

Description

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
    char str[100],s[100];
    int t;
    int lenstr, lens;
    while (scanf("%d", &t) != EOF && t != -1) {
        scanf("%s %s", str, s);
        lenstr = strlen(str);
        lens = strlen(s);

        int n = 0, j, i, m = lenstr-1;
        int flag = 0;

        for (i = 0; i < lens; i++) {
            flag = 1;
            for (j = 0; j < lenstr; j++) {
                if (s[i] == str[j]) {
                    flag = 0;
                    str[j] = '#';
                    m--;
                }
            }
            if (1 == flag && j >= lenstr)
                n++;
            if (n > 6 || m < 0)
                break;
        }

        printf("Round %d\n", t);
        if (n <= 6 && m < 0)
            printf("You win.\n");
        else if (n > 6)
            printf("You lose.\n");
        else
            printf("You chickened out.\n");
    }

    return 0;
}
发布了399 篇原创文章 · 获赞 440 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/Aibiabcheng/article/details/105479768