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. python 6 循环

    循环 要计算1+2+3,我们可以直接写表达式: >>> 1 + 2 + 3 6 要计算1+2+3+...+10,勉强也能写出来. 但是,要计算1+2+3+...+10000,直接写表 ...

  2. 使用命令行创建Android工程报错:"Target id is not valid. Use 'android.bat list targets' to get the target ids"

    D:\adt\sdk>cd tools D:\adt\sdk\tools> D:\adt\sdk\tools>android list targets Available Andro ...

  3. Spring MVC 示例

    Srping MVC项目结构如下: 一.首先创建一个Dynamic Web Project 二.WebContent/WEB-INF/文件夹下新增 web.xml,配置servlet 容器对于web. ...

  4. 【翻译转载】【官方教程】Asp.Net MVC4入门指南(6):验证编辑方法和编辑视图

    本节中,您将开始修改为电影控制器所新加的操作方法和视图.然后,您将添加一个自定义的搜索页. 在浏览器地址栏里追加/Movies, 浏览到Movies页面.并进入编辑(Edit)页面. Edit(编辑) ...

  5. IO流----转换流、缓冲流

    打开一个文本文件,另存为: Ansi就是系统默认编码(就是gbk) 建一个编码是utf-8的txt文件, 例: import java.io.FileWriter; import java.io.IO ...

  6. vue2.0:(六)、移动端像素border的实现和整合引入less文件

    知识点一.如何在手机上看我们制作的移动端页面. 正常我们在电脑上都是按如下图来制作手机页面的: 如果要在手机上面看就不能用localhost了.所以,进入命令行,输入ipconfig查看本地ip地址: ...

  7. Ubuntu批量修改权限

    Ubuntu中有两个修改命令可以用到,「change mode」&「change owner」 即chmod以及chown,其中可以用递归参数-R来实现更改所有子文件和子目录的权限. 1.利用 ...

  8. centos 安装 rtmp nginx 视频流服务器

    ---恢复内容开始--- 1.使用yum安装git yum -y install git 2.下载nginx-rtmp-module,官方github地址 // 通过git clone 的方式下载到服 ...

  9. 【开发小结】Two Steps from Deadline

    进度条可以救我也可以杀死我 # START 2018年4月17日晚我测试了11组四则运算的UI,每个exe程序生成的每一道题都有恐怖的倒计时.PSP表格清晰的记录了开发过程中消耗的时间,但是在结对作业 ...

  10. SharePoint Online 缺少“将站点另存为模板”

    之前文章行给出在SharePoint 2010 .SharePoint 2013 中将站点保存模板选项的文章.其实同样的问题出现在Microsoft Office 365的一部分SharePoint ...