• UVa 489 Hangman Judge


     Hangman Judge 

    Time limit: 3.000 seconds

    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.

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int i = 0, j, n, len, flag[101];
        char ch[101], chance, t;
        while(scanf("%d", &n) != EOF && n != -1)
        {
            memset(ch, 0, sizeof(ch));
            memset(flag, 0, sizeof(flag));
            scanf("%s", ch);
            getchar();
            len = strlen(ch);
            for(i=0; i<=7;)
            {
                t = 0;
                chance = getchar();
                if(i == 7 && chance != '\n') continue;   
                else if(chance == '\n') break;
                for(j=0; j<len; j++)
                {
                    if(ch[j] == chance)
                    {
                        t = 1;
                        flag[j] = 1;
                    }
                }
                if(t == 0) i++;
            }
            printf("Round %d\n", n);
                for(j=0; j<len && flag[j] == 1; ++j);
                if(j<len) {if(i != 7)printf("You chickened out.\n");
                          else printf("You lose.\n");
                }else printf("You win.\n");
            
        }
        return 0;
    }

    解题报告:
    这题可以说是简单题,分情况写代码,题目背景可以忽略,做这题的时间差不多用了我两个小时,仅仅是因为考虑情况不周,WA了两次,
    再者因Valladolid的OJ不允许输入注释掉的语句“//”CE了两次。题目如此简单,为何耗时如此之多,我想原因是:1> 看到题目觉得是简单题,
    不像其他题要想一段时间才有思路,但没想到就算一简单题无明确的思路去做只会手忙脚乱,更不用说要达到一次通过的情况了。2>未摒弃急躁的心,
    既然想一次AC,为何还要用在线判题,MoreIP的是题目做得太少了
  • 相关阅读:
    rt_list_entry() 函数
    替换空格
    跳台阶
    斐波那契数列
    基于5221码的同步十进制加法计数器
    强连通分量+Tarjia+缩点
    次小生成树
    差分约束
    P1547 Out of Hay
    P1197 [JSOI2008]星球大战
  • 原文地址:https://www.cnblogs.com/liaoguifa/p/2742480.html
Copyright © 2020-2023  润新知