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\n",t);
if(_false == 7)
printf("You lose.\n");
else if(_false <7 && se.size() != 0)//没有错误7次同时也没有找完,放弃
printf("You chickened out.\n");
else
printf("You win.\n");
}
return 0;
}

水题:UVa489-Hangman Judge的更多相关文章

  1. 【紫书】uva489 Hangman Judge 做了很久Orz

    题目链接:https://vjudge.net/problem/UVA-489 题意:给出两行字符串,第一行是标准答案,第二行是玩家猜的串.玩家每次猜一个,猜对一个,标准答案中所有该字符都算被猜到.猜 ...

  2. UVA489 - Hangman Judge【紫书例题4.2】

    题意:就是给出一个字符串,让你去一个一个猜测,相同字母算一次,如果是之前猜过的也算错,如果你在错7次前猜对就算你赢,文章中是LRJ的例题代码. #include<stdio.h> #inc ...

  3. HDU ACM 1073 Online Judge -&gt;字符串水题

    分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...

  4. 【例题4-2 uva489】Hangman Judge

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 水题. 中间就赢了算赢.(重复说,算错 [代码] #include <bits/stdc++.h> using name ...

  5. hdu 2050:折线分割平面(水题,递归)

    折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. hdu 2044:一只小蜜蜂...(水题,斐波那契数列)

    一只小蜜蜂... Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...

  7. hdu 2041:超级楼梯(水题,递归)

    超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

  8. 动态规划之HDU水题

    做水题的感觉真好系列 HDU 2084 数塔 1: 12: 1 23: 1 2 34: 1 2 3 45: 1 2 3 4 5 dp[i][j]第i行第j个数取得的最大值dp[i][j] = max( ...

  9. hdu5360 Hiking(水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Hiking Time Limit: 6000/3000 MS (Java/Oth ...

随机推荐

  1. E. Mike and Foam 容斥原理

    http://codeforces.com/problemset/problem/548/E 这题是询问id,如果这个id不在,就插入这个id,然后求a[id1] ,  a[id2]互质的对数. 询问 ...

  2. Oracle更新表字段时内容中含有特殊字符&的解决方法

    今天在做 Oracle表字段更新时出现了特殊字符&,导致无法更新. 这个问题是第二次碰到了,所以在此记录下,以备后用. 举例: update t set col1='A&B' wher ...

  3. 从typeof()说起

    本文也同步发表在我的公众号“我的天空” 首先我们先思考一下,执行下列语句分别会显示什么? alert(typeof(Array)); alert(typeof(Array())); 我们进入正题! 在 ...

  4. ae(ArcEngine) java swing开发入门系列(1):开发环境和代码部署

    前言:做ae开发大部分人都是用C#版,很少用到java版,本系列文章主要介绍java版ae开发的入门,对于ae接口的高级应用,可以看C#版相关文章 开发环境软件: Intellij IDEA 2018 ...

  5. 变更gcc版本

    当前的GCC版本为GCC-4.2,需要切换到GCC-3.4.首先,你需要去你的usr/bin/下去看看有没有gcc-3.4这样文件,如果没有的话,就安装一下吧: apt-get install gcc ...

  6. Web Api2中使用Session

    要在webApi里面使用Session必须在Global.asax插入 public override void Init() { this.PostAuthenticateRequest += (s ...

  7. Elasticsearch-基本操作2

    Elasticsearch版本:6.0 为了避免并发修改的冲突问题,数据库中,经常用悲观锁和乐观锁来控制并发问题,而Elasticsearch使用乐观锁.如果源数据在读写过程中被修改,更新将失败,应用 ...

  8. 云计算的那些「What」

    本文从云计算讲起,介绍了选择云计算的各种理由和一些最基本的概念. 经过十多年发展,云计算早已成为不可阻挡的技术潮流,逐渐深入到各行各业,不同规模的组织中,帮助用户以更低运营成本获得完善高效的 IT 服 ...

  9. Caused by: java.lang.ClassNotFoundException: org.springframework.web.socket.server.standard.ServerEndpointExporter

    Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/web/socket/ ...

  10. 【UML】状态图Statechart diagram(转)

    前言         UML由动态图和静态图组成,状态图就是属于动态图中较为重要的一张图. 定义         用来描述一个特定对象的所有可能状态以及由于各种事件的发生而引起的状态之间的转移. 目的 ...