UVa 489 Hangman Judge(字符串)
| Hangman Judge |
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.
一个字符串的游戏 有一个你不知道的字符串 你開始有7条命 然后你每次猜一个字母 若你猜的字母在原字符串中 原字符串就去掉全部那个字母 否则你失去一条命 假设你在命耗完之前原字符串中全部的字母都被猜出 则你赢 假设你在命耗完了原字符串中还有字母没被猜出 则你输 假设你在命没耗完原字符串中也还有字母没被猜出 视为你放弃
给你还有一个字符串作为你猜的顺序 推断你能否赢:
//UVa489 Hangman
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1000;
char a[N], b[N];
int cas, la, lb, i, j;
int main()
{
while (scanf ("%d", &cas), cas + 1)
{
scanf ("%s %s", a, b);
la = strlen (a);
lb = strlen (b);
int ca[26] = {0}, left = 7;
for (i = 0; i < la; ++i)
++ca[a[i] - 'a'];
for (i = 0; i < lb; ++i)
if (ca[b[i] - 'a'] != 0)
{
ca[b[i] - 'a'] = 0;
for (j = 0; j < 26; ++j)
if (ca[j] != 0) break;
if (j == 26)
{
printf ("Round %d\nYou win.\n", cas);
break;
}
}
else if (--left == 0)
{
printf ("Round %d\nYou lose.\n", cas);
break;
}
if (i == lb) printf ("Round %d\nYou chickened out.\n", cas);
}
return 0;
}
UVa 489 Hangman Judge(字符串)的更多相关文章
- uva 489 Hangman Judge(水题)
题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...
- uva 489.Hangman Judge 解题报告
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 489 Hangman Judge (字符匹配)
题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+ ...
- uva 489 Hangman Judge
大意:电脑想个单词,玩家来猜.玩家输入一个个字母,若答案里有这个字母,则显示该单词中所有该字母.最终目标是显示答案所有字母.猜错7次,死: 注意特殊条件:1.玩家不断重复错误的字母,只算一次猜错.2. ...
- uvaoj 489 - Hangman Judge(逻辑+写代码能力)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Hangman Judge UVA - 489
In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each gam ...
- UVa 489 HangmanJudge --- 水题
UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...
- UVA.12169 Disgruntled Judge ( 拓展欧几里得 )
UVA.12169 Disgruntled Judge ( 拓展欧几里得 ) 题意分析 给出T个数字,x1,x3--x2T-1.并且我们知道这x1,x2,x3,x4--x2T之间满足xi = (a * ...
- UVA 12169 Disgruntled Judge 扩展欧几里得
/** 题目:UVA 12169 Disgruntled Judge 链接:https://vjudge.net/problem/UVA-12169 题意:原题 思路: a,b范围都在10000以内. ...
随机推荐
- 关于ds添加datarow
有一个dataset DS.如果我想将DS中的某一行复制,得到新的一行,添加到DS中. 可能就会想到:DS.Tables[0].Rows.Add(DS.Tables[0].Rows[i])但是这样程序 ...
- Python 开发初识
从今天开始记录自己的python开发之路,用博客记录自己的学习经历,以及学习小结,小的项目模块,努力充实,做最好的自己!!!
- Exceptions & Errors - 异常与错误
来源于 Ry’s Objective-C Tutorial - RyPress 一个学习Objective-C基础知识的网站. 个人觉得很棒,所以决定抽时间把章节翻译一下. 本人的英语水平有限,有让大 ...
- Java实现打包文件
把文件打包到压缩包里 public void zip (String... files) throws IOException { //创建文件打包流对象 ZipOutputStream zos = ...
- adb 命令收藏学习地址
adb 命令相关的网页https://www.cnblogs.com/medsonk/p/8334847.htmlhttps://www.cnblogs.com/medsonk/p/6959658.h ...
- 利用gsoap库封装易用的rest框架
c++缺少web开发的框架,web框架分为异步和同步,异步的业务逻辑控制需要较强功底,同步代码实现起来容易,利于阅读理解 1.gsoap是c++写的webservice库,webservice应用层也 ...
- NOIP 2018 真・退役记
目录 NOIp 2018 真・退役记 7.01 7.05 \(summary\) 7.12 7.18 7.26 - 7.27 8.2 8.3 8.3 8.7 8.9 8.20 8.24 8.27 8. ...
- 魂酥的NOIP2018(真实)游记
NOIP之后才开博客 作为一个高一零基础蒟蒻 想说什么似乎也没什么可说的 才学几个月似乎也没什么发言权就是了 Day -1 期中考爆0,似乎是班里学OI的考得最惨的一个 岂不美哉 要么我也没想考好 也 ...
- MyBatis 中 resultMap 详解
resultMap 是 Mybatis 最强大的元素之一,它可以将查询到的复杂数据(比如查询到几个表中数据)映射到一个结果集当中.如在实际应用中,有一个表为(用户角色表),通过查询用户表信息展示页面, ...
- linux环境下时间的查看和修改
查看日期和时间date 查看时区date -R 查看UTC时间date -u 修改日期[root@centos ~]# date -s 20181230Sun Dec 30 00:00:00 EST ...