UVa 489 Hangman Judge(字符串)

 Hangman Judge 

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:

  1. The contestant tries to solve to puzzle by guessing one letter at a time.
  2. 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.‘‘
  3. 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
       | /|\
       |  |
       | / \
     __|_
     |   |______
     |_________|
  4. If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word, the contestant loses.
  5. If the contestant has guessed all the characters of the word before the drawing is 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 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.

一个字符串的游戏  有一个你不知道的字符串  你开始有7条命  然后你每次猜一个字母  若你猜的字母在原字符串中  原字符串就去掉所有那个字母  否则你失去一条命   如果你在命耗完之前原字符串中所有的字母都被猜出  则你赢   如果你在命耗完了原字符串中还有字母没被猜出  则你输    如果你在命没耗完原字符串中也还有字母没被猜出  视为你放弃

给你另一个字符串作为你猜的顺序  判断你是否能赢:

//UVa489 Hangman
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1000;
char a[N], b[N];
int cas, la, lb, i, j;
int main()
{
    while (scanf ("%d", &cas), cas + 1)
    {
        scanf ("%s %s", a, b);
        la = strlen (a);
        lb = strlen (b);
        int ca[26] = {0}, left = 7;
        for (i = 0; i < la; ++i)
            ++ca[a[i] - 'a'];
        for (i = 0; i < lb; ++i)
            if (ca[b[i] - 'a'] != 0)
            {
                ca[b[i] - 'a'] = 0;
                for (j = 0; j < 26; ++j)
                    if (ca[j] != 0) break;
                if (j == 26)
                {
                    printf ("Round %d\nYou win.\n", cas);
                    break;
                }
            }
            else if (--left == 0)
            {
                printf ("Round %d\nYou lose.\n", cas);
                break;
            }
        if (i == lb) printf ("Round %d\nYou chickened out.\n", cas);
    }
    return 0;
}

UVa 489 Hangman Judge(字符串)

时间: 2024-12-22 14:37:40

UVa 489 Hangman Judge(字符串)的相关文章

uva 489.Hangman Judge 解题报告

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=430 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 using namespace std; 6 7 con

UVA 489 Hangman Judge (字符匹配)

题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+1. 2.当错误次数达到7时,游戏结束,输了lose. 3.当串A中已经没有字符了,游戏结束,赢了win.(串B后面还没遍历到的也不用遍历了) 4.当错误次数没到达7,但是字符串A还有剩下的字符没消去,则chickened out. 错满7个就输,在满7个之前匹配完了就赢,在满7个之前没匹配完就ch

UVa 489 Hangman Judge

题目大意: 这是一个猜单词的游戏. 输入回合数(但回合数为-1的时候停止) 再输入一个待猜的单词B 最后输入你猜的单词组合A. 这个猜单词比较有意思的地方是他一个一个判断. 从你输入的A中,按照顺序一个一个字母来判断. 当B中有这个字母的时候,这个字母就被标记(所有在B中相同的都被标记). 当B中没有这个字母的时候,就统计一次错. 若 所以字母都被标记了则获胜, 错误达到7次则失败. 若 判断完错误还不足7次, 也没标记完,则视为放弃. ★一定要注意是一个一个判断 Sample Input 1

uva 489

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 contesta

uva489 Hangman Judge (模拟)

题目链接: 啊哈哈,选我选我 思路是:对猜测的字符串进行扫描..看最后猜错的次数是不是大于等于7,还有就是已经踩过的数字在猜算错误,所以用map判一下重即可..如果知道这个坑,那么就是水马题.  Hangman Judge  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

【UVA】12169-Disgruntled Judge(暴力or欧几里得)

可能由于后台数据的原因,这道题直接暴力枚举a,b进行判断也能过,不过跑的时间长,效率太差了. 14021006 12169 Disgruntled Judge Accepted C++ 0.876 2014-08-11 08:46:28 不说了,比较无脑. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #incl

UVA489 Hangman Judge

题意:给一个小写字母序列,然后猜测一串序列,每猜到一个字母第一个序列的所以这个字母就显示出来,如果没有猜到就画一笔,画到七笔后就算输,所有字母都显示出来后就算赢,如果没画到7笔并且用来猜测的序列字母已用完,则输出You chickened out #include <iostream> #include<stdio.h> #include<string> #include<cstring> #include<cmath> #include<

UVa 489 HangmanJudge --- 水题

UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜过的单词也算出错, 给定计算机的单词以及猜测序列,判断玩家赢了(You win).输了(You lose).放弃了(You chickened out) /* UVa 489 HangmanJudge --- 水题 */ #include <cstdio> #include <cstring

HDOJ/HDU 1073 Online Judge(字符串处理~)

Problem Description Ignatius is building an Online Judge, now he has worked out all the problems except the Judge System. The system has to read data from correct output file and user's result file, then the system compare the two files. If the two f