水题: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 ...
随机推荐
- SSIS父子维度
1.数据仓库结构: 2.区域的AttributeHierarchyVisible设置为False 3.Parent ID的Usage设置为Parent 4.级别命名: 5.结果:
- java中接口(interface)和虚基类(abstract class)的区别
在Java语言中,abstract class和interface是支持抽象类定义的两种机制.正是由于这两种机制的存在,才赋予了Java强大的面向对象能力.abstract class和interfa ...
- spring事务的开启方式(编程式和声明式)
1.编程式事务:编码方式实现事务管理(代码演示为JDBC事务管理) Spring实现编程式事务,依赖于2大类,分别是上篇文章提到的PlatformTransactionManager,与模版类Tran ...
- 函数补充:动态参数,函数嵌套,global与nonlocal关键
一丶动态参数 1.*args 位置参数,动态传参 def func(*food): print(food) print(func("米饭","馒头"," ...
- They say Rome wasn't built in a day, and yet what a difference a day makes.
They say Rome wasn't built in a day, and yet what a difference a day makes.有人说罗马不是一天建成的,但一天却能改变很多事.
- [拾零]C语言的数组指针
为了强化记忆,从而写笔记保留. 数组指针,顾名思义,是在说一个指针,这个指针是指向数组的. 区别于指针数组 int* p[5] = NULL; //指针数组 基类型 int* int (*p)[5] ...
- (五)SpringMVC之使用Kaptcha实现验证码功能
一.什么是Kaptcha Kaptcha是Google开发的用于自动生成验证码的插件. 二.怎么导入Kaptcha ① 如果没有用Maven管理工具的话就直接导入包(可以直接下载:pau8) http ...
- UVA 10891 Game of Sum (决策优化)
这是一个零和博弈,最高得分只和序列以及谁先手有关. d[i][j],表示i到j的序列当前取的这个人的最高得分,转移以后状态是新的区间和另一个人取,从中取最小值. 决策的最小值也可递推. #includ ...
- Android(java)学习笔记108:Android的Junit调试
1. Android的Junit调试: 编写android应用的时候,往往我们需要编写一些业务逻辑实现类,但是我们可能不能明确这个业务逻辑是否可以成功实现,特别是逻辑代码体十分巨大的时候,我们不可能一 ...
- wine卸载
Wine手动卸载,出现殘留,导致安装其他软件也不成功. 错误如下: 正在读取软件包列表... 完成正在分析软件包的依赖关系树 正在读取状态信息... 完成 您也许需要运行“ap ...