UVa 489:Hangman Judge

Posted xietx1995

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVa 489:Hangman Judge相关的知识,希望对你有一定的参考价值。

题目传送门:UVa 489:Hangman Judge

#include <stdio.h>
#include <string.h>
char ans[100], gus[100];
int left, chance; // left剩余未被猜出的字符数,错误chance次就会输
bool win, lose;

void guess(char ch)

    bool right = false;
    for (int i = 0; i < ans[i]; ++i)
        if (ans[i] == ch)  left--; ans[i] = '*'; right = true; 
    if (!right) --chance;
    if (0 == chance) lose = true;
    if (0 == left) win = true;


int main()

    int rnd, lengus;
    while (scanf("%d%s%s", &rnd, ans, gus) == 3 && rnd != -1)
    
        printf("Round %d\\n", rnd);
        win = lose = false;
        chance = 7;
        left = strlen(ans);
        lengus = strlen(gus);
        for (int i = 0; i < lengus; ++i)
        
            guess(gus[i]);
            if (win || lose) break;
        
        if (win) printf("You win.\\n");
        else if (lose) printf("You lose.\\n");
        else printf("You chickened out.\\n");
    

以上是关于UVa 489:Hangman Judge的主要内容,如果未能解决你的问题,请参考以下文章

UVA 489-- Hangman Judge(暴力串处理)

UVa 489:Hangman Judge

uva 489 Hangman Judge

UVa 489 -- Hangman Judge

UVa 489 HangmanJudge --- 水题

uva489