풀이
문제에 기술되어 있는 내용을 정확히 코드로 구현합니다.
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
// your code goes here
int R;
while (cin >> R) {
if (R == -1) {
break;
}
cout << "Round " << R << endl;
string solution, guesses;
cin >> solution >> guesses;
int Stroke = 0;
while(guesses.length()>0) {
char ch = guesses[0];
if ( solution.find(ch) == -1 ) {
Stroke += 1;
} else {
solution.erase(remove(solution.begin(), solution.end(), ch), solution.end());
}
guesses.erase(remove(guesses.begin(), guesses.end(), ch), guesses.end());
if (Stroke >= 7) {
break;
}
if (solution.length() == 0) {
break;
}
}
if (solution.length() == 0) {
cout << "You win." << endl;
} else if (Stroke >= 7) {
cout << "You lose." << endl;
} else if (guesses.length() == 0) {
cout << "You chickened out." << endl;
}
}
return 0;
}
'알고리즘 트레이닝 > UVa' 카테고리의 다른 글
441 - Lotto (0) | 2019.11.06 |
---|---|
146 - ID Codes (0) | 2019.11.04 |
573 - The Snail (0) | 2019.11.02 |
11799 - Horror Dash (0) | 2019.11.02 |
11559 - Event Planning (0) | 2019.11.02 |