UVa489

題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=430

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
#include <bits/stdc++.h>

using namespace std;

int main(){
ios::sync_with_stdio(0);
cin.tie(0);

int kase;

string password;
string guess;
while(cin >> kase){
if(kase == -1) break;
cin >> ws;
getline(cin, password);
getline(cin, guess);

unordered_set<char> s, guessed;
for(char c : password) s.insert(c);

int wrong = 0;
int all = s.size(), correct = 0;

for(char current : guess){
if(wrong == 7 || correct == all) break;
if(guessed.count(current)) continue;
guessed.insert(current);
if(s.count(current)){
correct++;
s.erase(current);
}
else{
wrong++;
}

}

cout << "Round " << kase << '\n';
if(wrong == 7){ // lose
cout << "You lose.\n";
}
else if(s.empty()){ // win
cout << "You win.\n";
}
else{ // chickened out
cout << "You chickened out.\n";
}
}

return 0;
}