zoukankan      html  css  js  c++  java
  • 水题:UVa489-Hangman Judge

    Hangman Judge

    Time limit 3000 ms

    Description

    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 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 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.


    解题心得:

    1. 紫书上的的一个题,很简单,就是判断一下就可以了,使用set可以很轻松的解决。

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e5;
    char s[maxn],s1[maxn];
    int  main()
    {
        int t;
        while(scanf("%d",&t) && t != -1)
        {
            set <char> se;
            set<char>::iterator iter;
            int _false = 0;
            scanf("%s%s",s,s1);
    
            int len = strlen(s);
            int len1 = strlen(s1);
    
            for(int i=0;i<len;i++)
                se.insert(s[i]);//将第一个字符串中的所有出现过的字母放在set里面
            for(int i=0;i<len1;i++)
            {
                if(se.size() == 0)
                    break;//set中的字幕完全显示出来了
                iter = se.find(s1[i]);//在目标串中找字母
                if(iter != se.end())
                    se.erase(s1[i]);//找到后就删去
                else
                    _false++;//没找到也记录一下
                if(_false == 7)
                    break;
            }
    
            printf("Round %d
    ",t);
            if(_false == 7)
                printf("You lose.
    ");
            else if(_false <7 && se.size() != 0)//没有错误7次同时也没有找完,放弃
                printf("You chickened out.
    ");
            else
                printf("You win.
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    Balsamiq Mockups完全手册[转]
    如何成为一个专家
    [ 转]discuz 的加密与解密函数authcode解析
    无题
    [转]Yahoo!网站性能最佳体验的34条黄金守则——内容
    唐僧的家书
    Webservice超时问题
    c#类的初始化顺序
    智力逻辑题程序实现(生日猜测)
    Winform下重写Button按钮
  • 原文地址:https://www.cnblogs.com/GoldenFingers/p/9107281.html
Copyright © 2011-2022 走看看