// UVa 489 - Hangman Judge
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
int round;
while (cin >> round && round != -1) {
string word;
cin >> word;
set<char> leftToGuess, hiddenWord, previousGuesses;
for (int i = 0; i < word.length(); i++) {
leftToGuess.insert(word[i]);
hiddenWord.insert(word[i]);
}
cin >> word;
int wrongLeft = 7;
for (int i = 0; i < word.length(); i++) {
bool wrongGuess = hiddenWord.find(word[i]) == hiddenWord.end() && previousGuesses.find(word[i]) == previousGuesses.end();
if (wrongGuess) {
wrongLeft--;
if (wrongLeft == 0)
break;
}
previousGuesses.insert(word[i]);
leftToGuess.erase(word[i]);
if (leftToGuess.empty())
break;
}
cout << "Round " << round << endl;
if (wrongLeft == 0)
cout << "You lose." << endl;
else if (leftToGuess.empty())
cout << "You win." << endl;
else
cout << "You chickened out." << endl;
}
return 0;
}
Monday, March 6, 2017
UVa 489 - Hangman Judge
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment