水题: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.
解题心得:
- 紫书上的的一个题,很简单,就是判断一下就可以了,使用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的更多相关文章
- 【紫书】uva489 Hangman Judge 做了很久Orz
题目链接:https://vjudge.net/problem/UVA-489 题意:给出两行字符串,第一行是标准答案,第二行是玩家猜的串.玩家每次猜一个,猜对一个,标准答案中所有该字符都算被猜到.猜 ...
- UVA489 - Hangman Judge【紫书例题4.2】
题意:就是给出一个字符串,让你去一个一个猜测,相同字母算一次,如果是之前猜过的也算错,如果你在错7次前猜对就算你赢,文章中是LRJ的例题代码. #include<stdio.h> #inc ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
- 【例题4-2 uva489】Hangman Judge
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 水题. 中间就赢了算赢.(重复说,算错 [代码] #include <bits/stdc++.h> using name ...
- hdu 2050:折线分割平面(水题,递归)
折线分割平面 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 2044:一只小蜜蜂...(水题,斐波那契数列)
一只小蜜蜂... Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...
- hdu 2041:超级楼梯(水题,递归)
超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...
- 动态规划之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( ...
- hdu5360 Hiking(水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Hiking Time Limit: 6000/3000 MS (Java/Oth ...
随机推荐
- Ubuntu 16.04 以太坊开发环境搭建
今天我们来一步一步从搭建以太坊智能合约开发环境. Ubuntu16.04 安装ubuntu16.04.下载链接 //先update一下(或者换国内源再update) sudo apt-get upda ...
- 浅谈C#解析网页
最近做了一个项目,要求获取各大主流网页上的关键信息,本人以前了解过网页爬虫的知识,所以想到了网页爬虫了实现功能 第一次尝试: 采用webclient获取远程网页的内容,然后采用正则表达式进行过滤 但, ...
- 编译安装php容易出现的问题以及解决办法
http://crybit.com/20-common-php-compilation-errors-and-fix-unix/
- Flat UI theme--扁平化的UI
项目地址:点击打开 支持版本: jQuery Mobile 1.3.2 使用很简单,前提是你的前端是在jquery-mobile的基础上开发的,然后导入相应的css文件.img文件和js文件即可. 案 ...
- Java的API及Object类、String类、字符串缓冲区
Java 的API 1.1定义 API: Application(应用) Programming(程序) Interface(接口) Java API就是JDK中提供给开发者使用的类,这些类将底层的代 ...
- Android tess_two Android图片文字识别
文字识别一般都用的tesseract-ocr. GitHub:https://github.com/tesseract-ocr/tesseract 而Android对应的比较推荐的有个tess-two ...
- Android 自定义Adapter中实现startActivityForResult的分析
最近几天在做文件上传的时候,想在自定义Adapter中启动activity时也返回Intent数据,于是想到了用startActivityForResult,可是用mContext怎么也调不出这个方法 ...
- Nginx服务器301跳转到带www的域名的方法
为什么要这么做? 我们的域名在做解析时经常会解析2个域名,即带www的和不带www的.这样做的目的是,当用户使用不带www的域名时,也可以正常访问你的网站.但是这样做的后果是,你站点主域名的PR值分散 ...
- android测试开发环境搭建
本文档针对未接触过android的0基础人员,在开始熟悉android之前,首先需要一个学习环境来支撑,在此简单介绍一下android环境搭建.(当然大家也可以百度.谷歌,类似的文档很多) 环境搭建: ...
- 如何处理SAP云平台错误消息 there is no compute unit quota for subaccount
当我试图部署一个应用到SAP云平台的neo环境时: 指定Compute Unit Size为Lite: 点击Deploy按钮,遇到如下错误消息:there is no compute unit quo ...