UVA-489 Hangman Judge

Source: Internet
Author: User

In the "Hangman Judge," You is to the write a program that judges a series of the Hangman games. For each game, the answer to the puzzle are given as well as the guesses. Rules is the same as the classic game of Hangman, and is given as follows:

1. The contestant tries to solve to puzzle by guessing one letter at a time.

2. Every time a guess is correct, all of the characters in the word that match the guess would be ' turned over. ' For example, if your guess is ' o ' and the word was "book", then both ' o ' in the solution would be counted as "solved".

3. Every time a wrong guess is made, a stroke'll be added to the drawing of a hangman, which needs 7 strokes to complete . Each unique wrong guess is only counts against the contestant once.

4. If the drawing of the hangman is completed before the contestant have successfully guessed all the characters of the WOR D, the contestant loses.

5. If the contestant have guessed all the characters of the word before the drawing are complete, the contestant wins the GA Me.

6. If The contestant does not guess enough letters to either win or lose, the contestant chickens out. Your task as the "Hangman Judge" is-determine, for each game, whether-contestant wins, loses, or fails to finish a Game.

Input
Your program would be given a series of inputs regarding the status of a game. All input would be in the lower case. The first line of all sections would contain a number to indicate which round of the game is being played; The next line is being the solution to the puzzle; The last line was 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 was to indicate which round of the game the contestant are currently playing as well as the Resul T of the game. There is three possible results:you win. You lose. You are chickened out.

Sample Input
1

Cheese

Chese

2

Cheese

Abcdefg

3

Cheese

Abcdefgij

-1

Sample Output
Round 1

You win.

Round 2

You are chickened out.

Round 3

You lose.

The difficulty of this problem has the following several:

    1. Understand: "You are chickened out." Is what kind of situation;
    2. Realize "guess an already guessed letter is wrong";
    3. Maintain a large number of variables;

Solve:

    1. "You are chickened out." It means to give up without guessing (not yet dead, but not yet guessed right to press the ENTER key);
    2. "Guess an already-guessed letter is wrong" can be used to make the already guessed letter into a space ' to implement (put the statement in the loop, once the string in the guess of the same letter as the original string, then the original string all the letter is assigned to a space, so that the letter will be read again when the error is not found);
    3. Use global variables;

The code is as follows:

1#include <stdio.h>2#include <string.h>3 #defineMAXN 1004 intLeft , Chance;5 CharS[MAXN], S2[MAXN];6 intwin, lose;7  8 voidGuessCharch) {9     intBad =1;Ten      for(intI=0; I<strlen (s); i++){ One         if(S[i] = =ch) { Aleft--; -S[i] =' '; -Bad =0; the         } -     } -     if(bad)--chance; -     if(!chance) Lose =1; +     if(!left) win =1; - } +   A intMain () at { -     intRnd; -      while(SCANF ("%d", &rnd) && rnd! =-1){ -scanf"%s", s); - GetChar (); -scanf"%s", S2); inprintf"Round%d\n", RND); -Win = lose =0; toleft =strlen (s); +Chance =7; -          for(intI=0; I<strlen (S2); i++){ the guess (s2[i]); *             if(Win | | lose) Break; $         }Panax Notoginseng         if(Win) printf ("You win.\n"); -         Else if(lose) printf ("You lose.\n"); the         Elseprintf"You chinkened out.\n"); +     } A     return 0; the}

UVA-489 Hangman Judge

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.