Hangman Judge UVA - 489
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.
先贴一份用字符串做错的代码把
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #define maxn 105
- using namespace std;
- int main()
- {
- int n;
- while(cin >> n)
- {
- if(n==-)
- break;
- char str1[maxn],str2[maxn];
- cin >> str1 >> str2;
- int num = ;
- int flg = ;
- for(int i=;i<strlen(str2);i++)
- {
- int flag = ;
- if(num>=)
- break;
- for(int j=;j<strlen(str1);j++)
- {
- if(str2[i] == str1[j])
- {
- flag = ;
- int k;
- for(k=j;k<strlen(str1)-;k++)
- {
- str1[k] = str1[k+];
- }
- str1[k] = '\0';
- break;
- }
- }
- if(!flag)
- {
- num++;
- flg = ;
- }
- }
- if(num>=)
- {
- cout << "Round " << n << endl;
- cout << "You lose." << endl;
- }
- else
- {
- if(flg)
- {
- cout << "Round " << n << endl;
- cout << "You win." << endl;
- }
- else
- {
- cout << "Round " << n << endl;
- cout << "You chickened out." << endl;
- }
- }
- }
- return ;
- }
在师傅的提醒下用set做的...
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<set>
- using namespace std;
- int main()
- {
- int n;
- while(cin >> n)
- {
- if(n==-)
- break;
- string str1,str2;
- cin >> str1 >> str2;
- int num = ;
- set<char> s;
- for(int i=;i<str1.length();i++)
- s.insert(str1[i]);//用set简单很多,用字符串老是错。。
- for(int i=;i<str2.length();i++)
- {
- if(!s.size() || num>=)
- break;
- if(s.find(str2[i]) == s.end())
- num++;
- else s.erase(str2[i]);
- }
- if(num>=)
- {
- cout << "Round " << n << endl;
- cout << "You lose." << endl;
- }
- else
- {
- if(!s.size())
- {
- cout << "Round " << n << endl;
- cout << "You win." << endl;
- }
- else
- {
- cout << "Round " << n << endl;
- cout << "You chickened out." << endl;
- }
- }
- }
- return ;
- }
Hangman Judge UVA - 489的更多相关文章
- 刽子手游戏(Hangman Judge, UVa 489)
刽子手游戏其实是一款猜单词游戏,游戏规则是这样的:计算机想一个单词让你猜,你每次可以猜一个字母.如果单词里有那个字母,所有该字母会显示出来:如果没有那个字母,则计算机会在一幅“刽子手”画上填一笔.这幅 ...
- 例题4-2 刽子手游戏(Hangman Judge, UVa 489)
#include<stdio.h> #include<string.h> int ok ,no; int left ,chance; char s[20] ,s2[20]; v ...
- UVa 489 Hangman Judge(字符串)
Hangman Judge In ``Hangman Judge,'' you are to write a program that judges a series of Hangman gam ...
- UVa 489 HangmanJudge --- 水题
UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...
- uva 489.Hangman Judge 解题报告
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- uva 489 Hangman Judge(水题)
题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...
- uva 489 Hangman Judge
大意:电脑想个单词,玩家来猜.玩家输入一个个字母,若答案里有这个字母,则显示该单词中所有该字母.最终目标是显示答案所有字母.猜错7次,死: 注意特殊条件:1.玩家不断重复错误的字母,只算一次猜错.2. ...
- UVA 489 Hangman Judge (字符匹配)
题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+ ...
- uvaoj 489 - Hangman Judge(逻辑+写代码能力)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- IDEA自学
使用Eclipse很长时间了,想换个IDE用,都说IDEA好用,今天试试 百度了一下IDEA,了解到IDEA社区版免费,上百度,下载个社区版(exe,zip两种)懒人选择exe 手动安装别怕安错,只管 ...
- 完全零基础在Linux中安装 JDK
完全零基础在Linux中安装 JDK 总体思路:先确定没有Java程序了 — 然后创建相应路径文件夹 — 下载JDK — 解压到当前路径 — 自定义文件名称 — 配置环境变量 — 检查是否安装成功 第 ...
- Adapter适配器模式--图解设计模式
第二章: Adapter 模式 Adapter模式分为两种: 1.类适配器模式 2.委托适配器 我看的是<图解设计模式>这本书,这小鬼子说的话真难懂,只能好好看代码理解. 先说适配器模式要 ...
- 封装 Gson 解析Json到对象是否失败
在使用Google的 Gson 类库解析 Json 数据时,难免会出现解析失败的情况. 在这种情况下,使用 if(obj == null) 是不可行的,fromJson 方法会自动生成对象的实例,所以 ...
- BFS DFS模板
转载于https://blog.csdn.net/alalalalalqp/article/details/9155419 BFS模板: #include<cstdio> #include ...
- xcode自动刷新resource下的文件
修改resource下的lua或者ccbi文件时,xcode并不会察觉到,所以需要手动清理xcode缓存和模拟器缓存,开发效率比较低下. 通过以下步骤可以实现自动刷新resource下的文件,且无需手 ...
- 转载 | 一种让超大banner图片不拉伸、全屏宽、居中显示的方法
现在很多网站的Banner图片都是全屏宽度的,这样的网站看起来显得很大气.这种Banner一般都是做一张很大的图片,然后在不同分辨率下都是显示图片的中间部分.实现方法如下: <html> ...
- 算法与数据结构基础 - 字典树(Trie)
Trie基础 Trie字典树又叫前缀树(prefix tree),用以较快速地进行单词或前缀查询,Trie节点结构如下: //208. Implement Trie (Prefix Tree)clas ...
- RE最全面的正则表达式----字符验证
二.校验字符的表达式汉字:^[一-彪]{0,}$英文和数字:^[A-Za-z0-9]+$ 或 ^[A-Za-z0-9]{4,40}$长度为3-20的所有字符:^.{3,20}$由26个英文字母组成的字 ...
- eclipse插件——maven
项目开发中遇到的问题 都是同样的代码,为什么在我的机器上可以编译执行,而在他的机器上就不行? 为什么在我的机器上可以正常打包,而配置管理员却打不出来? 项目组加入了新的人员,我要给他说明编译环境如何设 ...