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:

  1. The contestant tries to solve to puzzle by guessing one letter at a time.
  2. 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.''
  3. 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
    | /|\
    | |
    | / \
    __|_
    | |______
    |_________|
  4. If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word, the contestant loses.
  5. If the contestant has guessed all the characters of the word before the drawing is complete, the contestant wins the game.
  6. 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(字符串)的更多相关文章

  1. uva 489 Hangman Judge(水题)

    题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  2. uva 489.Hangman Judge 解题报告

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. UVA 489 Hangman Judge (字符匹配)

    题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+ ...

  4. uva 489 Hangman Judge

    大意:电脑想个单词,玩家来猜.玩家输入一个个字母,若答案里有这个字母,则显示该单词中所有该字母.最终目标是显示答案所有字母.猜错7次,死: 注意特殊条件:1.玩家不断重复错误的字母,只算一次猜错.2. ...

  5. uvaoj 489 - Hangman Judge(逻辑+写代码能力)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. Hangman Judge UVA - 489

    In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each gam ...

  7. UVa 489 HangmanJudge --- 水题

    UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...

  8. UVA.12169 Disgruntled Judge ( 拓展欧几里得 )

    UVA.12169 Disgruntled Judge ( 拓展欧几里得 ) 题意分析 给出T个数字,x1,x3--x2T-1.并且我们知道这x1,x2,x3,x4--x2T之间满足xi = (a * ...

  9. UVA 12169 Disgruntled Judge 扩展欧几里得

    /** 题目:UVA 12169 Disgruntled Judge 链接:https://vjudge.net/problem/UVA-12169 题意:原题 思路: a,b范围都在10000以内. ...

随机推荐

  1. 网页内容爬取:如何提取正文内容 BEAUTIFULSOUP的输出

    创建一个新网站,一开始没有内容,通常需要抓取其他人的网页内容,一般的操作步骤如下: 根据url下载网页内容,针对每个网页的html结构特征,利用正则表达式,或者其他的方式,做文本解析,提取出想要的正文 ...

  2. 阿里云机器学习tensorflow实践

    1,前言 伴随人工智能和深度学习的应用越来越普及,越来越多的开发人员开始投入到智能算法的编程中.由于算法成熟且公开,软件编码这一块不存在难度:但模型训练和预测所需的时间与硬件设备的配置有极大关系,很多 ...

  3. php redis 操作大全

    类和方法 用法 Redis类 类RedisException 预定义的常量 Redis类 说明:创建一个Redis客户端 例 $redis = new Redis(); 类RedisException ...

  4. Eclipse 编译java文件后出错 左树无红叉

    问题描述: 今天遇见让人郁闷的问题,在项目工程中java文件编译通不过,eclipse在java文件中标示错误,但是却不不能在navigator的视图中像平常一样出现小红叉.通过clean proje ...

  5. vuex理解之modules小记

    好记性不如烂笔头 demo预览 源代码 前情提要 关于vuex,其实很久以前就研究使用过,还研究过 flux,redux之类的体系,当时感觉对于 state,action,dispatch,views ...

  6. OpenTSDB监控

    OpenTSDB监控

  7. HTML <section> 标签

    实例 文档中的区段,解释了 PRC: <section>   <h1>PRC</h1>   <p>The People's Republic of Ch ...

  8. dorado 7 使用总结

    最近项目上需要,使用了dorado 7 ,总体感觉还可以,快速开发很方便,然而在方便的同时,难免有些太过繁琐,很多东西都封装了起来,会造成很多不便.因此快速开发的项目可以使用,其它的不推荐.现在打算将 ...

  9. UVA - 820 Internet Bandwidth(最大流模板题)

    题目: 思路: 直接套最大流的模板就OK了,注意一下输出的格式. 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define M ...

  10. Manacher算法(马拉车算法)浅谈

    什么是Manacher算法? 转载自百度百科 Manachar算法主要是处理字符串中关于回文串的问题的,它可以在 O(n) 的时间处理出以字符串中每一个字符为中心的回文串半径,由于将原字符串处理成两倍 ...