UVA - 489 Hangman Judge(set应用)

游戏开发与AI音视频处理技术综述
本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并重点介绍了AI音视频处理在游戏开发中的应用,如语义识别、语音识别、AR效果等,为游戏开发者提供了一站式的解决方案和技术指南。
部署运行你感兴趣的模型镜像


 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.


题目大意:
Hangman Judge是一个猜英文单字的小游戏(在电子字典中常会看到),游戏规则如下:
1.答案单字写在纸上(每个字符一张纸),并且被盖起来,玩家每次猜一个英文字符(letter)。
2.如果这个英文字符猜中(在答案的英文单字中有出现),被猜中的字符就被翻开。例如:答案是book,如果你猜o,book中的两个o就会被视为已猜中。
3.如果这个英文字符未出现在答案的单字中,就会在hangman的图中多加一划。要完成hangman图共需7划,如下图。注意:同一个猜错的字符只能再图上画一划,例如:答案是book,第一次你猜a(未猜中)会在图上画一划,但第二次以后再猜a并不会再多画。
4.如果在hangman图完成之前,玩家已猜中所有答案中的字符,则玩家赢(win)。
5.如果玩家尚未猜中所有答案中的字符而hangman图完成了,,则玩家输(lose)。
6.如果玩家在还没输赢的情况之下就不玩了,那我们说玩家胆小放弃了(chicken out)。


解析:这题主要用到了set集合,分别用三个set来存放,s1中的字符,s2和s1相同的字符,s1中不存在的字符,

如果不存在的字符超过7个lost,如果s1中的字符 和 s2和s1相同的字符个数一样多就win,否则chicken out。

#include <stdio.h>
#include <string.h>
#include <set>
using namespace std;
const int N = 500;
char s1[N];
char s2[N];
int main() {
	int cas;
	set<char> v1; //保存s1的字符
	set<char> v2; //保存s2中与s1相同的字符
	set<char> v3; //保存s1中不存在的字符
	while(scanf("%d",&cas) != EOF && cas != -1) {
		printf("Round %d\n",cas);
		scanf("%s%s",s1,s2);	
		int len1 = strlen(s1);
		int len2 = strlen(s2);
		for(int i = 0; i < len1; i++) {
			v1.insert(s1[i]);
		}
		int i;
		for(i = 0; i < len2; i++) {
			bool flag = true;
			for(int j = 0; j < len1; j++) {
				if(s2[i] == s1[j]) {
					v2.insert(s2[i]);
					flag = false;
					break;
				}
			}
			if(flag) {
				v3.insert(s2[i]);
			}
			if(v3.size() == 7) {
				printf("You lose.\n");
				break;
			}
			if(v1.size() == v2.size()) {
				printf("You win.\n");
				break;
			}
		}
		if( i == len2) {
			printf("You chickened out.\n");
		}
		v1.clear();
		v2.clear();
		v3.clear();
	}
	return 0;
}

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.9

TensorFlow-v2.9

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值