Ultraviolet A 489-Hangman Judge

Source: Internet
Author: User

Hangman Judge
In ''hangman Judge, ''you are writing 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 in 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 wocould 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. question: Enter n for each group of data, which indicates the group of data. The second row is the string to be guessed, and the third row is the string to be guessed. If you have guessed a letter, it means you have guessed all the letters in the first string that you guessed are correct. If all the letters in the first string are guessed right, output you win. If the number of wrong guesses reaches 7 times, output You lose. Otherwise, output You chickened out.

# Include <stdio. h> # include <string. h> int stroke; int s [105];/* indicates whether the letter in the first string has been guessed */int JudgeCorrect (char * a, char * B) {int cnt, i, j, flag; stroke = 0;/* Number of wrong guesses */cnt = 0;/* Number of right guesses */memset (s, 0, sizeof (s); for (I = 0; I <strlen (B); I ++) {flag = 0; if (stroke = 7) break; for (j = 0; j <strlen (a); j ++) {if (B [I] = a [j] &! S [j]) {s [j] = 1; cnt ++; flag = 1 ;}} if (! Flag) stroke ++;} return cnt;} int main () {int I, j, cases, count, flag; char guess [105], answer [105]; while (~ Scanf ("% d", & cases) & cases! =-1) {getchar (); gets (answer); gets (guess); count = JudgeCorrect (answer, guess); printf ("Round % d \ n ", cases); if (count = strlen (answer)/* completely guessed */printf ("You win. \ n "); else if (stroke = 7)/* The number of guesses reaches 7 */printf (" You lose. \ n "); elseprintf (" You chickened out. \ n ") ;}return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.