In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follows:
- The contestant tries to solve to puzzle by guessing one letter at a time.
- Every time a guess is correct, all the characters in the word that match the guess will be ``turned over.'' For example, if your guess is ``o'' and the word is ``book'', then both ``o''s in the solution will be counted as ``solved.''
- Every time a wrong guess is made, a stroke will be added to the drawing of a hangman, which needs 7 strokes to complete. Each unique wrong guess only counts against the contestant once.
______ | | | O | /|\ | | | / \ __|_ | |______ |_________|
- If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word, the contestant loses.
- If the contestant has guessed all the characters of the word before the drawing is complete, the contestant wins the game.
- If the contestant does not guess enough letters to either win or lose, the contestant chickens out.
Your task as the ``Hangman Judge'' is to determine, for each game, whether the contestant wins, loses, or fails to finish a game.
Input
Your program will be given a series of inputs regarding the status of a game. All input will be in lower case. The first line of each section will contain a number to indicate which round of the game is being played; the next line will be the solution to the puzzle; the last line is a sequence of the guesses made by the contestant. A round number of -1 would indicate the end of all games (and input).
Output
The output of your program is to indicate which round of the game the contestant is currently playing as well as the result of the game. There are three possible results:
You win. You lose. You chickened out.
Sample Input
1 cheese chese 2 cheese abcdefg 3 cheese abcdefgij -1
Sample Output
Round 1 You win. Round 2 You chickened out. Round 3 You lose.
题目大意:
1. 答案单字写在纸上(每个字符一张纸),并且被盖起来,玩家每次猜一个英文字符(letter)。
2. 如果这个英文字符猜中(在答案的英文单字中有出现),被猜中的字符就被翻开。例如:答案是book,如果你猜o,book中的两个o就会被视为已猜中。
3. 如果这个英文字符未出现在答案的单字中,就会在hangman的图中多加一划。要完成hangman图共需7划,如下图。注意:同一个猜错的字符只能再图上画一划,例如:答案是book,第一次你猜a(未猜中)会在图上画一划,但第二次以后再猜a并不会再多画。
4. 如果在hangman图完成之前,玩家已猜中所有答案中的字符,则玩家赢(win)。
5. 如果玩家尚未猜中所有答案中的字符而hangman图完成了,,则玩家输(lose)。
6. 如果玩家在还没输赢的情况之下就不玩了,那我们说玩家胆小放弃了(chicken out).
用字符串遍历,规则同上;
#include <iostream> #include <cstring> #include <cstdio> using namespace std; int main() { int n; char a[105]; char c[105]; int b[105]; while(cin>>n) { if(n==-1) break; getchar();//去掉空格; memset(b,1,max);//清一 gets(a);//输入 gets(c); cout<<"Round "<<n<<endl; int count=0,flag; int l=strlen(a); int l2=strlen(c); for(int i=0; i<l2; i++) { flag=0; if(b[c[i]-'a']) { for(int j=0; j<l; j++) { if(c[i]==a[j]) { a[j]='0';//遍历过的清零; flag=1; } } b[c[i]-'a']=0; if(!flag) count++; } if(count==7) { cout<<"You lose."<<endl; flag=1; break; } flag=1; for(int j=0; j<l; j++) { if(a[j]!='0')//遍历完成后还有a中没出现的字符; { flag=0; break; } } if(flag) { cout<<"You win."<<endl; break; } } if(!flag) cout<<"You chickened out."<<endl; } return 0; }