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.

又是一道串处理的题,感觉模拟题大多跟串有关 orz。

这道题是模拟一个猜字谜游戏,一共同拥有两个串 第一个串是字谜的答案一開始都是翻着的(就是在反面 看不到),第二个串你猜的答案。对于你的答案。从左往右遍历,假设这个字符在答案中出现过。那么将答案串中全部包括这个字母的卡片都翻开,假设猜错了(就是答案串中找不到这个字符) 罚时加一(罚时7以上就算输了),并且,假设当前字母猜错了,以后再猜这个不加罚时。(比方答案中没有a 你第一次猜a 罚时加一,以后再猜a 不加罚时)假设在罚时限制内全猜完了,就算赢,假设在罚时时间内没猜完(意思是串遍历到头还没猜完但罚时也不到7)就算逃跑。

依据游戏特点,能够对输入的两个串分别进行删除反复字母处理(这点我不知道有没有必要,只是我那挫代码貌似比人家跑的慢了好多好多。。

大概就是这的问题)。然后以下模拟游戏操作就能够了

#include<cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
char s[1010], g[1010], t1[1010], t2[1010];
int main()
{
int round, i, j, flag; while (cin >> round && round != -1)
{
int p = 0, q = 0;
cin >> s >> g; for (i = 0; i < strlen(s); i++)//去掉反复字母
{
flag = 1; for (j = 0; j < i; j++)
{
if (s[j] == s[i])
{
flag = 0;
break;
}
} if (flag)
{
t1[p++] = s[i];
}
} for (i = 0; i < strlen(g); i++)//去掉反复字母
{
flag = 1; for (j = 0; j < i; j++)
{
if (g[j] == g[i])
{
flag = 0;
break;
}
} if (flag)
{
t2[q++] = g[i];
}
} cout << "Round " << round << endl;
int cnt = 0, sum = 0, ok = 1; for (i = 0; i < q; i++)
{
int f = 1; for (j = 0; j < p; j++)
{
if (t2[i] == t1[j])
{
f = 0;
break;
}
} if (f)
{
cnt++;//统计罚时
}
else
{
sum++;//统计已猜对的字母的个数
} if (sum == p && cnt < 7)
{
ok = 0;
cout << "You win." << endl;
break;
} if (cnt >= 7)
{
ok = 0;
cout << "You lose." << endl;
break;
}
} if (ok)
{
cout << "You chickened out." << endl;
}
} return 0;
}

UVA 489-- Hangman Judge(暴力串处理)的更多相关文章

  1. UVa 489 Hangman Judge(字符串)

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

  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(水题)

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

  5. uva 489 Hangman Judge

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

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

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

  7. Hangman Judge UVA - 489

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

  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. 二分搜索(Binary Search)

    当我们在字典中查找某个单的时候,一般我们会翻到一个大致的位置(假设吧,翻到中间位置),开始查找.如果翻到的正好有我们要的词,那运气好,查找结束.如果我们要找的词还在这个位置的前面,那我们对前面的这一半 ...

  2. js点击事件防止用户重复点击执行

    点击事件里给button标签加一个自定义属性,存上次点击时间 追问: 求详细代码,JS 真心的没怎么做过 追答:   <input type="button" id=&quo ...

  3. VMware 虚拟机的网络连接方式详解

         VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式).要想在网络管理和维护中合理应用它们,你就应该先了解一下这三种工作 ...

  4. Oracle游标动态赋值

    1. oracle游标动态赋值的小例子 -- 实现1:动态给游标赋值 -- 实现2:游标用表的rowtype声明,但数据却只配置表一行的某些字段时,遍历游标时需fetch into到精确字段 CREA ...

  5. 采用标准c进行目录文件遍历

    图像处理的时候经常需要对一个目录的所有图像进行处理,遍历文件得c代码: 在windows中需要使用到宽字符. 另外,可以使用opencv封装的目录访问操作,下次给出. // DirTraverse.c ...

  6. 基于angularJS和requireJS的前端架构

    1.概要描述 1.1.angularJS描述:angularJS是可以用来构建WEB应用的,WEB应用中的一种端对端的完整解决方案.通过开发者呈现一个更高层次的抽象来简化应用的开发.最适合的就是用它来 ...

  7. sshd安全性能优化

    sshd服务是远程登录服务,默认端口为22,对于其优化一是为了增加服务器的安全,避免暴力破解:二是为了加快速度连接,减少不必要的带宽的浪费. sshd服务的配置文件为/etc/ssh/sshd_con ...

  8. js 创建html元素 渲染html元素

    var p1 = document.getElementById('p1'); //添加的元素类型及属性var newNode = document.createElement("input ...

  9. Java中使用webservice,简化开发(xfire的webservice)

    首先,使用到的jar先导入项目中, xbean-spring-2.8.jar, wsdl4j-1.6.1.jar, commons-httpclient-3.0.jar, commons-codec- ...

  10. Mac下Apache服务器配置

    一.Apache服务器 1. 使用最广的 Web 服务器 2. Mac自带,只需要修改几个配置就可以,简单,快捷 3. 有些特殊的服务器功能,Apache都能很好的支持 目的:让有一个自己专属的测试环 ...