博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 489-- Hangman Judge(暴力串处理)
阅读量:6121 次
发布时间:2019-06-21

本文共 3568 字,大约阅读时间需要 11 分钟。

  

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.

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).

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.

1cheesechese2cheeseabcdefg3cheeseabcdefgij-1

Round 1You win.Round 2You chickened out.Round 3You lose.

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

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

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

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

#include
#include
#include
#include
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;}

转载地址:http://hxgka.baihongyu.com/

你可能感兴趣的文章
配置设置[Django]引入模版之后报错Requested setting TEMPLATE_DEBUG, but settings are not configured....
查看>>
下一步工作分配
查看>>
Response. AppendHeader使用大全及文件下载.net函数使用注意点(转载)
查看>>
Wait Functions
查看>>
代码描述10313 - Pay the Price
查看>>
jQuery最佳实践
查看>>
centos64i386下apache 403没有权限访问。
查看>>
vb sendmessage 详解1
查看>>
jquery用法大全
查看>>
Groonga 3.0.8 发布,全文搜索引擎
查看>>
PC-BSD 9.2 发布,基于 FreeBSD 9.2
查看>>
网卡驱动程序之框架(一)
查看>>
css斜线
查看>>
Windows phone 8 学习笔记(3) 通信
查看>>
重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush
查看>>
Revit API找到风管穿过的墙(当前文档和链接文档)
查看>>
Scroll Depth – 衡量页面滚动的 Google 分析插件
查看>>
Windows 8.1 应用再出发 - 视图状态的更新
查看>>
自己制作交叉编译工具链
查看>>
Qt Style Sheet实践(四):行文本编辑框QLineEdit及自动补全
查看>>