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

1.两个字符窜进行判断,第二个字符窜是第一个字符窜的匹配,若第二个字符窜的字母能够完全匹配上第一个就win
2.若第一个字符窜的一个字母被判断过了,以后出现相同的字母无论是否匹配都不算数,而第二个字符窜的一个字符用过了,以后再用若能够匹配则不计数,若不能够匹配,错的计数就加一次
#include<stdio.h>
#include<string.h>
const int MAXN=1000;

int main()
{
    int n,i,j,k;
    int ans,flag;
    int cas=1;
    int len,len_word,len_guess;
    char str1[MAXN],str2[MAXN];
    while(scanf("%d",&n))
    {
        ans=flag=len_word=len_guess=0;
        if(n==-1) break;
        scanf("%s",str1);
        scanf("%s",str2);
        for (i=0;str1[i];i++)//去掉相同的
        {
            if(str1[i]!=1)
            {
                for (j=i+1;str1[j];j++)
                {
                    if(str1[i]==str1[j]) str1[j]=1;
                }
            }
        }
        len=strlen(str1);
        printf("Round %d\n",n);
        for (i=0;str1[i];i++)//计算有几个要猜字母
        {
            if(str1[i]!=1) len_word++;
        }
        for (i=0;str2[i];i++)
        {
            if(str2[i]==2) continue;//该字母已经踩过了
            for (j=0;str1[j];j++)//猜对了
            {
                if(str2[i]==str1[j]) break;
            }
            if(j==len) ans++;//没猜对
            else 
            {
                len_guess++;
                for (j=i+1;str2[j];j++)//无论猜对猜错都要清楚掉
                {
                    if(str2[i]==str2[j]) str2[j]=2;
                }
            }
            if(len_word==len_guess)
            {
                flag=1;
                printf("You win.\n");
                break;
            }
            else if(ans==7) 
            {
                flag=1;
                printf("You lose.\n");
                break;
            }            
        }
        if(!flag) printf("You chickened out.\n");
    }
    return 0;
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Netkiller

GSON 多层Map剥离

工作中遇到一个问题,我们提供给外包方的 json 无法Decode 。 一段简单 JSON 字符串,字符串如下。 String json= "{\"0\":{...

3104
来自专栏数据之美

简化你的 java 字符串操作:Guava 之 CharMatcher 用法简介

对字符串的处理应该是编程活动中最频繁的操作了,而原生的 JDK 以及 Java 本身的语法特性使得在 Java 中进行字符串操作是一件极其麻烦的事情,如果你熟...

3318
来自专栏行者常至

020.Java的反射机制

JAVA反射机制是在运行状态中, 对于任意一个类,都能够知道这个类的所有属性和方法; 对于任意一个对象,都能够调用它的任意方法和属性; 这种动态获取信息以...

851
来自专栏深度学习与计算机视觉

算法-调整数组顺组使奇数位于偶数前面

题目: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,偶数位于数组的后半部分。 解题思路: 比如我们有一个这样...

2067
来自专栏C#

数组未必一定需从0开始,谈一下非0开始的数组

  谈到数组时,当被问及数组是从什么数开始时,估计大部分程序员都会直接说出数组当然是从0开始的。这个回答当然没有错,现在我们就来了解一下C#中的下限非...

1905
来自专栏函数式编程语言及工具

Scalaz(13)- Monad:Writer - some kind of logger

  通过前面的几篇讨论我们了解到F[T]就是FP中运算的表达形式(representation of computation)。在这里F[]不仅仅是一种高阶类型...

18910
来自专栏博客园

.NET面试题解析(02)-拆箱与装箱

装箱和拆箱几乎是所有面试题中必考之一,看上去简单,就往往容易被忽视。其实它一点都不简单的,一个简单的问题也可以从多个层次来解读。

1414
来自专栏鸿的学习笔记

简单定义Python和Scala的类和对象

在现代编程语言里,类和对象都是绕不过的话题。对象这个概念可以是生活的抽象,为了更好的理解使用书来做比喻,每一本书都是一个对象,也就是一个实例,书本身具有的页码等...

821
来自专栏GreenLeaves

C# 装箱和拆箱

C#的值类型可以分为在栈上分配内存的值类型和在托管堆上分配内存的引用类型。 1、那么值类型和引用类型能否相互转换呢? 答案是肯定的,C#通过装箱和拆箱来实现两者...

19810
来自专栏二进制文集

FastJSON 源码分析

Fastjson是一个Java语言编写的高性能功能完善的JSON库。它采用一种“假定有序快速匹配”的算法,把JSON Parse的性能提升到极致,是目前Java...

2042

扫码关注云+社区

领取腾讯云代金券