uva 489 Hangman Judge

本文介绍了一个简单的Hangman游戏胜负判断程序。该程序接收输入的游戏轮次、答案及玩家猜测,然后判断玩家是否获胜、失败或放弃游戏。通过跟踪正确和错误的猜测次数来决定游戏结果。

489 - Hangman Judge
Time limit: 3.000 seconds

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:

The contestant tries to solve to puzzle by guessing one letter at a time.
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.''
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     
   | /|\   
   |  |     
   | / \   
 __|_      
 |   |______
 |_________|

If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word, the contestant loses.
If the contestant has guessed all the characters of the word before the drawing is complete, the contestant wins the game.
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).

#include <stdio.h>
#include <string.h>
int main()
{
    int cases;
    char ch2[105],ch1[105];
    int p[105];
    while(scanf("%d",&cases)!=EOF&&cases!=-1)
    {
        memset(p,0,sizeof(p));
        printf("Round %d\n",cases);
        int win=0,lose=0,flag=0;
        getchar();
        gets(ch1);
        gets(ch2);
        int l1=strlen(ch1);
        int l2=strlen(ch2);
        for(int i=0;i<l2;i++)
        {
            flag=0;
            if(lose==7)
                break;
            for(int j=0;j<l1;j++)
            {
                if(ch2[i]==ch1[j]&&!p[j])
                {
                    p[j]=1;
                    win++;
                    flag=1;
                }
            }
            if(!flag)
                lose++;
        }
        if(win==l1)  
            printf("You win.\n");
        else if(lose==7) 
            printf("You lose.\n");
        else
            printf("You chickened out.\n");
    }
    return 0;
}
下载方式:https://pan.quark.cn/s/c9b9b647468b ### 初级JSP程序设计教程核心内容解析#### 一、JSP基础概述JSP(JavaServer Pages)是由Sun Microsystems公司创建的一种动态网页技术规范,主要应用于构建动态网站及Web应用。JSP技术使得开发者能够将动态数据与静态HTML文档整合,从而实现网页内容的灵活性和可变性。##### JSP的显著特性:1. **动态与静态内容的分离**:JSP技术支持将动态数据(例如数据库查询结果、实时时间等)嵌入到静态HTML文档中。这种设计方法增强了网页的适应性和可维护性。2. **易用性**:开发者可以利用常规的HTML编辑工具来编写静态部分,并通过简化的标签技术将动态内容集成到页面中。3. **跨平台兼容性**:基于Java平台的JSP具有优良的跨操作系统运行能力,能够在多种不同的系统环境中稳定工作。4. **强大的后台支持**:JSP能够通过JavaBean组件访问后端数据库及其他资源,以实现复杂的数据处理逻辑。5. **执行效率高**:JSP页面在初次被请求时会被转换为Servlet,随后的请求可以直接执行编译后的Servlet代码,从而提升了服务响应的效率。#### 二、JSP指令的运用JSP指令用于设定整个JSP页面的行为规范。这些指令通常放置在页面的顶部,向JSP容器提供处理页面的相关指导信息。##### 主要的指令类型:1. **Page指令**: - **语法结构**:`<%@ page attribute="value" %>` - **功能**:定义整个JSP页面的运行特性,如设定页面编码格式、错误处理机制等。 - **实例**: ...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值