标签:
问题链接: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\n", 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.\n"); else if(lose) printf("You lose.\n"); else printf("You chickened out.\n"); } return 0; }
标签:
原文地址:http://blog.csdn.net/tigerisland45/article/details/52186109