英语太烂啊。
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.两个字符窜进行判断,第二个字符窜是第一个字符窜的匹配,若第二个字符窜的字母能够完全匹配上第一个就win
2.若第一个字符窜的一个字母被判断过了,以后出现相同的字母无论是否匹配都不算数,而第二个字符窜的一个字符用过了,以后再用若能够匹配则不计数,若不能够匹配,错的计数就加一次
#include<stdio.h> #include<string.h> const int MAXN=1000; int main() { int n,i,j,k; int ans,flag; int cas=1; int len,len_word,len_guess; char str1[MAXN],str2[MAXN]; while(scanf("%d",&n)) { ans=flag=len_word=len_guess=0; if(n==-1) break; scanf("%s",str1); scanf("%s",str2); for (i=0;str1[i];i++)//去掉相同的 { if(str1[i]!=1) { for (j=i+1;str1[j];j++) { if(str1[i]==str1[j]) str1[j]=1; } } } len=strlen(str1); printf("Round %d\n",n); for (i=0;str1[i];i++)//计算有几个要猜字母 { if(str1[i]!=1) len_word++; } for (i=0;str2[i];i++) { if(str2[i]==2) continue;//该字母已经踩过了 for (j=0;str1[j];j++)//猜对了 { if(str2[i]==str1[j]) break; } if(j==len) ans++;//没猜对 else { len_guess++; for (j=i+1;str2[j];j++)//无论猜对猜错都要清楚掉 { if(str2[i]==str2[j]) str2[j]=2; } } if(len_word==len_guess) { flag=1; printf("You win.\n"); break; } else if(ans==7) { flag=1; printf("You lose.\n"); break; } } if(!flag) printf("You chickened out.\n"); } return 0; }