UVA_489:Hangman Judge

Language:C++ 4.8.2

#include<stdio.h>
#include<string.h>
int main(void)
{
    char str_original[30];
    char str_guessed[30];
    int arr_ori[30];
    int mark[30]; // 标记数组
    int n, fail_sum, success_sum, total_word;
    int ok; // 猜测成功与否的标志
    while(1)
    {
        scanf("%d\n", &n);
        if(n == -1)
            break;
        memset(arr_ori, 0, sizeof(arr_ori));
        memset(mark, 0, sizeof(mark));
        fail_sum = success_sum = total_word = 0;
        scanf("%s", str_original);
        scanf("%s", str_guessed);

        int len_ori = strlen(str_original);
        for(int i = 0; i < len_ori; i++)
        {
            arr_ori[str_original[i] - ‘a‘] = 1;
        }

        for(int i = 0; i < 30; i++)
        {
            if(arr_ori[i])
                total_word++;
        }
        int len_gue = strlen(str_guessed);

        int i;
        for(i = 0; i < len_gue; i++)
        {
            success_sum = 0;
            ok = 0;
            for(int j = 0; j < len_ori; j++)
            {
                if(str_guessed[i] == str_original[j])
                {
                    ok = 1;
                    mark[str_guessed[i] - ‘a‘] = 1;
                    break;
                }
            }
            for(int k = 0; k < 30; k++)
                if(mark[k]) success_sum++;

            if(success_sum == total_word)
            {
                printf("Round %d\nYou win.\n", n); // 去掉\n,WA
                break;
            }

            fail_sum += !ok;
            if(fail_sum == 7)
            {
                printf("Round %d\nYou lose.\n", n);
                break;
            }
        }
        if(i == len_gue)
            printf("Round %d\nYou chickened out.\n", n);
    }
    return 0;
}
时间: 2024-11-08 18:59:13

UVA_489:Hangman Judge的相关文章

UVA489 Hangman Judge

题意:给一个小写字母序列,然后猜测一串序列,每猜到一个字母第一个序列的所以这个字母就显示出来,如果没有猜到就画一笔,画到七笔后就算输,所有字母都显示出来后就算赢,如果没画到7笔并且用来猜测的序列字母已用完,则输出You chickened out #include <iostream> #include<stdio.h> #include<string> #include<cstring> #include<cmath> #include<

UVa 489 Hangman Judge(字符串)

 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 follo

uva489 Hangman Judge (模拟)

题目链接: 啊哈哈,选我选我 思路是:对猜测的字符串进行扫描..看最后猜错的次数是不是大于等于7,还有就是已经踩过的数字在猜算错误,所以用map判一下重即可..如果知道这个坑,那么就是水马题.  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

UVa 489 Hangman Judge

题目大意: 这是一个猜单词的游戏. 输入回合数(但回合数为-1的时候停止) 再输入一个待猜的单词B 最后输入你猜的单词组合A. 这个猜单词比较有意思的地方是他一个一个判断. 从你输入的A中,按照顺序一个一个字母来判断. 当B中有这个字母的时候,这个字母就被标记(所有在B中相同的都被标记). 当B中没有这个字母的时候,就统计一次错. 若 所以字母都被标记了则获胜, 错误达到7次则失败. 若 判断完错误还不足7次, 也没标记完,则视为放弃. ★一定要注意是一个一个判断 Sample Input 1

uva 489.Hangman Judge 解题报告

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=430 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 using namespace std; 6 7 con

UVA 489 Hangman Judge (字符匹配)

题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+1. 2.当错误次数达到7时,游戏结束,输了lose. 3.当串A中已经没有字符了,游戏结束,赢了win.(串B后面还没遍历到的也不用遍历了) 4.当错误次数没到达7,但是字符串A还有剩下的字符没消去,则chickened out. 错满7个就输,在满7个之前匹配完了就赢,在满7个之前没匹配完就ch

UVA 489-- Hangman Judge(暴力串处理)

 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 follo

UVA 489-- Hangman Judge--暴力串处理

 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 follo

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes