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.
先贴一份用字符串做错的代码把
#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的更多相关文章

  1. 刽子手游戏(Hangman Judge, UVa 489)

    刽子手游戏其实是一款猜单词游戏,游戏规则是这样的:计算机想一个单词让你猜,你每次可以猜一个字母.如果单词里有那个字母,所有该字母会显示出来:如果没有那个字母,则计算机会在一幅“刽子手”画上填一笔.这幅 ...

  2. 例题4-2 刽子手游戏(Hangman Judge, UVa 489)

    #include<stdio.h> #include<string.h> int ok ,no; int left ,chance; char s[20] ,s2[20]; v ...

  3. UVa 489 Hangman Judge(字符串)

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

  4. UVa 489 HangmanJudge --- 水题

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

  5. uva 489.Hangman Judge 解题报告

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

  6. uva 489 Hangman Judge(水题)

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

  7. uva 489 Hangman Judge

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

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

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

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

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

随机推荐

  1. Flutter学习笔记(13)--表单组件

    如需转载,请注明出处:Flutter学习笔记(13)--表单组件 表单组件是个包含表单元素的区域,表单元素允许用户输入内容,比如:文本区域,下拉表单,单选框.复选框等,常见的应用场景有:登陆.注册.输 ...

  2. Drawable与 Bitmap 转换总结

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android Drawable 使用方法详解请看上篇文章. Drawable 使用方法详解 本篇 ...

  3. Python基础编程 内置函数

    内置函数 内置函数(一定记住并且精通) print()屏幕输出 int():pass str():pass bool():pass set(): pass list() 将一个可迭代对象转换成列表 t ...

  4. mac安装ElasticSearch+head+node+一个例子~

    1.下载ElasticSearch 官网下载链接:https://www.elastic.co/cn/downloads/past-releases(进去的可能会比较慢,网络好的情况下会好一些) 我下 ...

  5. javascript 异步请求封装成同步请求

    此方法是异步请求封装成同步请求,加上token验证,环境试用微信小程序,可以修改文件中的ajax,进行封装自己的,比如用axios等 成功码采用标准的 200 到 300 和304 ,需要可以自行修改 ...

  6. 变量Variable

    变量Variable 内存 #conding:utf-8 a = 1 #conding:utf-8 a = 1 b = a #conding:utf-8 a = 1 b = a a = 2 命名规则 ...

  7. go 学习笔记之有意思的变量和不安分的常量

    首先希望学习 Go 语言的爱好者至少拥有其他语言的编程经验,如果是完全零基础的小白用户,本教程可能并不适合阅读或尝试阅读看看,系列笔记的目标是站在其他语言的角度学习新的语言,理解 Go 语言,进而写出 ...

  8. 什么是HTML,HTML的简介,HTML结构

    html:超文本标记语言(Hyper Text Markup Language) ==============基本结构================= <html><!--最外层为 ...

  9. 从源码看Flask框架配置管理

    1 引言 Flask作为Python语言web开发的三大顶梁柱框架之一,对于配置的管理当然必不可少.一个应用从开发到测试到最后的产品发布,往往都需要多种不同的配置,例如是否开启调试模式.使用哪个数据库 ...

  10. (二十一)c#Winform自定义控件-气泡提示

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...