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 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<cstdio>
#include<cstring>
#include<iostream>
#include<map>
using namespace std;

const int maxn=1000+10;
char message[maxn],guess[maxn];
map<char,bool>mp;

int main()
{
    int Case,wrong,cal,pd;
    while(~scanf("%d",&Case))
    {
       if(Case==-1)  return 0;
       scanf("%s%s",message,guess);
       int len1=strlen(message);
       int len2=strlen(guess);
       pd=len1;
       wrong=0;
       for(int i=0;i<len2;i++)
          mp[guess[i]]=false;
       for(int i=0;i<len2;i++)//╡б╡Б
       {
           cal=0;
           if(mp[guess[i]])
                  wrong++;
           else
           {
               mp[guess[i]]=true;
               for(int j=0;j<len1;j++)//т╜нд
               {
                  if(guess[i]==message[j])
                  {
                      cal++;
                      pd--;
                  }
               }
               if(cal==0)
                wrong++;
            }
           if(wrong==7)
              break;
           if(pd==0)
             break;
       }
       cout<<"Round "<<Case<<endl;
       if(wrong==7)
           cout<<"You lose."<<endl;
       else if(pd==0)
           cout<<"You win."<<endl;
       else
           cout<<"You chickened out."<<endl;
    }
    return 0;
}

uva489 Hangman Judge (模拟)

时间: 2024-10-14 01:15:55

uva489 Hangman Judge (模拟)的相关文章

UVA489 Hangman Judge

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

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 follo

UVa 489 Hangman Judge

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

UVA_489:Hangman Judge

Language:C++ 4.8.2 #include<stdio.h> #include<string.h> int main(void) { char str_original[30]; char str_guessed[30]; int arr_ori[30]; int mark[30]; // 标记数组 int n, fail_sum, success_sum, total_word; int ok; // 猜测成功与否的标志 while(1) { scanf("

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

uva489

题意见紫书 代码很久以前写,不太简洁 因此再贴一个刘汝佳代码 #include<iostream> #include<cstring> using namespace std; const int N=26; int vis[10][N]; bool flag; bool sum(int *a) { for(int i=0;i<N;i++) if(a[i]) return false; return true; } int main() { int loop,ans=0,cn

算法练习(一)

昨天是个值得纪念的日子,我数学建模拿了推荐国家一等奖的名额,希望最后能顺利拿到国一吧.现在大三已经开学一个月了.这一个月因为社会实践评优的事情真的很忙,还好最后拿到了可能拿到的所有的奖项.结果自己把科研助手这件事给耽误了,今天去找马老师,结果马老师的实验室人已经满了.所以没办法,我可能又要去找其他老师了. 今年国家奖学金的名额里面没有我,没有就算了吧.卧薪尝胆,好好学习,这一学期至关重要.所以自己现在就要开始准备保研的机试,现在的训练非常重要,无论如何,这是自己未来要走的一步路.我现在最重要的就

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 follo