首页 > 其他分享 >UVa 489 Hangman Judge (模拟&字符串匹配)

UVa 489 Hangman Judge (模拟&字符串匹配)

时间:2023-04-12 11:40:03浏览次数:48  
标签:guess 31 will game Hangman 489 Judge contestant


489 - Hangman Judge

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=430

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

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.



完整代码:

/*0.075s*/

#include <cstdio>
#include <cstring>

bool x[27], y[27];
char a[30], b[30];

int main(void)
{
	int n;
	int t, k, i, lena, lenb;
	while (true)
	{
		scanf("%d", &n);
		if (n < 0)
			break;
		t = k = 0;
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));
		scanf("%s%s", a, b);
		lena = strlen(a), lenb = strlen(b);
		for (i = 0; i < lena; i++)
			x[a[i] & 31] = y[a[i] & 31] = true;
		for (i = 1; i < 27; i++)
			t += x[i];///至少要猜对t次
		for (i = 0; i < lenb; i++)
		{
			if (x[b[i] & 31] && y[b[i] & 31]) ///猜对
			{
				y[b[i] & 31] = false;///再猜同样的字母就无效了
				t--;
				if (t == 0)
					break;
			}
			else if (!x[b[i] & 31]) ///猜错
			{
				k++;
				if (k == 7)
					break;
			}
		}
		printf("Round %d\n", n);
		if (t == 0)
			puts("You win.");
		else if (k == 7)
			puts("You lose.");
		else
			puts("You chickened out.");
	}
	return 0;
}



标签:guess,31,will,game,Hangman,489,Judge,contestant
From: https://blog.51cto.com/u_5535544/6185322

相关文章

  • 【题解】P4898 [IOI2018] seats 排座位
    思路线段树。题意可以转化成每次判定有多少个前缀满足所有结点构成矩形。首先排除确定矩阵坐标再数答案的做法,因为太难。所以考虑如何对前缀进行判定。一个简单的想法是维护前\(i\)个点中\(x,y\)坐标的最值,但这样只能暴力看矩阵中的所有元素,跑得很慢。不妨思考一下合法......
  • ABB DSSR122 4899001-NK 执行各种各样的信号处理运营
    ABBDSSR1224899001-NK执行各种各样的信号处理运营数字信号处理(死后无子女。)的用途是数字处理例如通过计算机或更专门的数字信号处理器,执行各种各样的信号处理运营。这数字信号以这种方式处理的是一系列数字,它们表示样品的连续变量在时间、空间或频率等领域。在…里数字电子学......
  • 【NOI OpenJudge】【1.4】编程基础之逻辑表达式与条件分支
    01:判断数正负#include<cstdio>#include<iostream>usingnamespacestd;intmain(){intn;cin>>n;if(n>0){printf("positive\n");}elseif(n==0){printf("zero\n");}else{pri......
  • 【NOI OpenJudge】【1.2】编程基础之变量定义、赋值及转换
    01:整型数据类型存储空间大小#include<cstdio>intmain(){ inta;shortb; printf("%d%d",sizeof(a),sizeof(b)); return0;}02:浮点型数据类型存储空间大小#include<cstdio>intmain(){ floata;doubleb; printf("%d%d",sizeof(a),sizeof(b)); return......
  • 【NOI OpenJudge1789】算24(搜索)
    problem给定4个数,加减乘除4种运算以及括号把这4个数连接起来得到一个表达式。问是否存在一种方式使得得到的表达式的结果等于24。solution正常的中缀表达式枚举和计算难度都约等于0,麻烦的是括号的枚举和处理。这里只要求满足的结果,所以换一种方式拿掉括号——打乱顺序即可(括号的用......
  • P3489 [POI2009]WIE-Hexer 题解
    一、题目描述:大陆上有 n 个村庄,m 条双向道路,p 种怪物,k 个铁匠,铁匠都在一个村庄里,他可会给你打造他所能打造的所有剑,特定的剑可以对付特定的怪物,每条道路上都可......
  • Vjudge 3.14 训练解题报告
    比赛传送门\(\color{white}{password:3.1415926}\)A.Fibonacci-ish题意:定义一个序列为“Fibonacci-ish”的,当且仅当对任意\(2<i\len,a_i=a_{i-1}+a_{i-2}\)。给定......
  • P2489 [SDOI2011]迷宫探险 题解
    题意简述:一个\(n\timesm\)的带墙体单入口多出口迷宫中有\(k\)个陷阱,陷阱分为有害或无害,有害会使人掉血,给出所有垃圾的有害与无害的所有排列组成的概率,给定人的血量,求......
  • OpenJudge702 Crossing River过河问题
    题目链接:702:CrossingRiver题目大意为有n个人要过河,船最多乘两个人,给出每个人乘船时间,两人乘船时间由更慢者决定。求过河最短时间。有t组数据,输入数据组数t,对于每组数据,......
  • Oracle宕机之PMON (ospid: 248987): terminating the instance due to error 484(另附h
    数据库版本:11.2.0.4RAC环境操作系统版本:AsianuxServerrelease7.3数据库报错分析接到业务消息,应用无法访问,开发人员查看日志后发现无法连接数据库。查看数据库进程......