UVa 489 - Hangman Judge

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

中文網址

Solution

直接看出現哪些字母,去模擬猜的過程即可。

Code

UVa 489
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<cstdio>

int main()
{
int round;
while (scanf("%d", &round) && round != -1)
{
getchar();
bool used[26] = {}, ans[26] = {};
int count = 0, hangman = 7;
char c;

while ((c = getchar()) != '\n')
{
if (!used[c - 'a'])
{
used[c - 'a'] = true;
count++;
}

if (count == 26)
{
while ((c = getchar()) != '\n');
break;
}
}

while ((c = getchar()) != '\n')
{
int temp = c - 'a';
if (!ans[temp])
{
ans[temp] = true;
if (used[temp])
{
used[temp] = false;
count--;
}
else
hangman--;
}

if (!hangman || !count)
{
while ((c = getchar()) != '\n');
break;
}
}

printf("Round %d\n", round);
if (!hangman)
puts("You lose.");
else if (count)
puts("You chickened out.");
else
puts("You win.");
}

return 0;
}