zoukankan      html  css  js  c++  java
  • UVA489 Hangman Judge

    问题链接UVA489 Hangman Judge

    问题简述:(略),参见原题链接。

    问题分析:这是一个模拟题。

    程序说明:程序中定义了若干宏定义,使得程序可阅读性增强。函数guess()中的逻辑做了适当的改进,更加合理快速。


    AC的C语言程序如下:

    /* UVA489 Hangman Judge */
    
    #include <stdio.h>
    #include <string.h>
    
    #define TRUE  1
    #define FALSE 0
    #define MAXN 128
    
    char s[MAXN], t[MAXN];
    int win, lose, chance, left, lens, lent;
    
    void guess(char c)
    {
        int bad, i;
    
        bad = TRUE;
        for(i=0; i<lens; i++)
            if(s[i] == c) {
                if(--left == 0) {
                    win = 1;
                    return;
                }
                s[i] = ' ';
                bad = FALSE;
            }
    
        if(bad)
            if(--chance == 0)
                lose = TRUE;
    }
    
    int main(void)
    {
        int round, i;
    
        while(scanf("%d%s%s", &round, s, t) != EOF && round != -1) {
            printf("Round %d
    ", round);
    
            left = lens = strlen(s);
            lent = strlen(t);
    
            win = lose = FALSE;
            chance = 7;
    
            for(i=0; i<lent; i++) {
                guess(t[i]);
                if(win || lose)
                    break;
            }
    
            if(win)
                printf("You win.
    ");
            else if(lose)
                printf("You lose.
    ");
            else
                printf("You chickened out.
    ");
        }
    
        return 0;
    }


    参考链接:Hangman Judge


  • 相关阅读:
    操作系统典型调度算法
    C++ volatile 关键字
    vue class绑定 组件
    yarn 基本用法
    vscode 插件安装以及首选项配置
    git 多人协作
    git Feature分支
    git Bug分支
    git 分支策略
    git 解决冲突
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7564420.html
Copyright © 2011-2022 走看看