UVA 489--Hangman Judge (Violent string treatment)

Source: Internet
Author: User
Tags first string

Hangman Judge

In "Hangman Judge," You're to-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 and 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 is "book", then both "O ' s in the solution would be counted as" solved .‘‘
  3. Every time a wrong guess is made, a stroke would 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.

       ______      |  |        |  O        |/|\ | |        |/\     __|_        |   | ______ |_________|
  4. If the drawing of the hangman is completed before the contestant have successfully guessed all the characters of the word, The contestant loses.
  5. If The contestant have guessed all the characters of the word before the drawing are complete, the contestant wins the game.
  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

1cheesechese2cheeseabcdefg3cheeseabcdefgij-1

Sample Output

Round 1You win. Round 2You chickened out. Round 3You lose.

is also a string of problems, the feeling of the simulation is mostly related to the string Orz.

The problem is to simulate a crossword puzzle, a common one with two strings the first string is the answer to a crossword puzzle that starts with a flip (which is not visible on the opposite side), and the second string of the answer you guessed. For your answer. Walk from left to right, assuming that the character appears in the answer. Then the answer string all include the letter of the card is opened, assuming wrong (that is, the answer string can not find this character) penalty time plus one (more than 7 of the penalty if the loss), and, assuming the current letter guessed wrong, and then guess this does not add penalty. (for example, the answer does not have a you first guess a penalty time plus one, and then guess a without penalty) assume that the penalty limit within the full guess, even win, assuming in the penalty time without guessing (meaning that the string traverse head has not guessed but the penalty is less than 7) even escape.

According to the game features, can be the input of the two string to delete the repeated letter processing (this point I do not know if there is no need, but my code looks like a lot slower than others to run much more.

This is probably the problem). Then the following simulation game operation will be able to


#include <cstdio> #include <cstdlib> #include <iostream> #include <cstring>using namespace std; Char s[1010], g[1010], t1[1010], T2[1010];int main () {int round, I, J, Flag;while (Cin >> round && round! =- 1) {int p = 0, q = 0;cin >> s >> g;for (i = 0; I < strlen (s); i++)//Remove repeated letters {flag = 1;for (j = 0; J < i; j+ +) {if (s[j] = = S[i]) {flag = 0;break;}} if (flag) {t1[p++] = s[i];}} for (i = 0; i < strlen (g); i++)//Remove repeated letters {flag = 1;for (j = 0; J < i; J + +) {if (g[j] = = G[i]) {flag = 0;break;}} if (flag) {t2[q++] = G[i];}} cout << "Round" << Round << Endl;int cnt = 0, sum = 0, OK = 1;for (i = 0; i < Q; i++) {int f = 1;for (j = 0; J < P; j + +) {if (t2[i] = T1[j]) {f = 0;break;}} if (f) {cnt++;//statistical penalty}else{sum++;//Statistics The number of letters that have been guessed}if (sum = = P && CNT < 7) {OK = 0;cout << "you win." << Endl;break;} if (CNT >= 7) {OK = 0;cout << "You lose." << Endl;break;}} if (OK) {cout << "chickened out." << Endl;}} return 0;}










UVA 489--Hangman Judge (Violent string treatment)

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.