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;
}
【完美复现】面向配电网韧性提升的移动储能预布局与动态调度策略【IEEE33节点】(Matlab代码实现)内容概要:本文介绍了基于IEEE33节点的配电网韧性提升方法,重点研究了移动储能系统的预布局与动态调度策略。通过Matlab代码实现,提出了一种结合预配置和动态调度的两阶段优化模型,旨在应对电网故障或极端事件时快速恢复供电能力。文中采用了多种智能优化算法(如PSO、MPSO、TACPSO、SOA、GA等)进行对比分析,验证所提策略的有效性和优越性。研究不仅关注移动储能单元的初始部署位置,还深入探讨其在故障发生后的动态路径规划与电力支援过程,从而全面提升配电网的韧性水平。; 适合人群:具备电力系统基础知识和Matlab编程能力的研究生、科研人员及从事智能电网、能源系统优化等相关领域的工程技术人员。; 使用场景及目标:①用于科研复现,特别是IEEE顶刊或SCI一区论文中关于配电网韧性、应急电源调度的研究;②支撑电力系统在灾害或故障条件下的恢复力优化设计,提升实际电网应对突发事件的能力;③为移动储能系统在智能配电网中的应用提供理论依据和技术支持。; 阅读建议:建议读者结合提供的Matlab代码逐模块分析,重点关注目标函数建模、约束条件设置以及智能算法的实现细节。同时推荐参考文中提及的MPS预配置与动态调度上下两部分,系统掌握完整的技术路线,并可通过替换不同算法或测试系统进一步拓展研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值