-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP489.cpp
75 lines (69 loc) · 1.31 KB
/
P489.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <stdio.h>
#define LEN 10000
int readInt() {
int ret = 0;
int mult = 1;
char w[20];
gets(w);
for(int i = 0; i < 20; ++i) {
if(w[i] == '-') {
mult = -1;
continue;
}
if(!(w[i] >= '0' && w[i] <= '9'))
break;
ret = ret * 10 + (w[i]-'0');
}
return mult*ret;
}
int main() {
bool toGuess[26], guessed[26];
char c, word[LEN], guess[LEN];
while(true) {
int round = readInt();
if(round == -1)
return 0;
std::cout << "Round " << round << std::endl;
// Reset data:
for(int i = 0; i < 26; ++i) {
toGuess[i] = guessed[i] = false;
}
// Word to guess:
gets(word);
int left = 0;
for(int i = 0; isprint(c = word[i]); ++i) {
if(!toGuess[c-'a']) {
toGuess[c-'a'] = true;
++left;
}
}
// Play game:
int straws = 0;
gets(guess);
bool done = false;
for(int i = 0; isprint(c = guess[i]); ++i) {
if(guessed[c-'a'])
continue;
guessed[c-'a'] = true;
if(toGuess[c-'a']) {
--left;
if(left == 0) {
done = true;
std::cout << "You win." << std::endl;
break;
}
}
else {
++straws;
if(straws == 7) {
done = true;
std::cout << "You lose." << std::endl;
break;
}
}
}
if(!done)
std::cout << "You chickened out." << std::endl;
}
}