uva 489.Hangman Judge 解题报告

时间:2023-09-21 19:46:38

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=430

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std; const int maxn = ; int l, chance;
char s[maxn], s2[maxn];
int win, lose; void guess(char ch)
{
int bad = ;
for (int i = ; i < strlen(s); i++) {
if (s[i] == ch) {
l--;
s[i] = '#';
bad = ;
}
}
if (bad) --chance;
if (!chance) lose = ;
if (!l) win = ;
} int main()
{
int rnd;
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
while (scanf("%d%s%s", &rnd, s, s2) == && rnd != -) {
printf("Round %d\n", rnd);
win = lose = ;
l = strlen(s);
chance = ;
for (int i = ; i < strlen(s2); i++) {
guess(s2[i]);
if (win || lose) break;
} if (win) printf("You win.\n");
else if (lose) printf("You lose.\n");
else printf("You chickened out.\n");
}
return ;
}