例题4-2 刽子手游戏(Hangman Judge,UVa 489)

Canace ·
更新时间:2024-11-15
· 792 次阅读

原题链接:https://vjudge.net/problem/UVA-489
分类:函数
备注:水题
前言:只要好好理解了题目意思就OK了,深感做题理解题意的重要性,好好学英语啊!

代码如下:

#include #include void solve(char* s1, char* s2) { int left = 7, len1 = strlen(s1), len2 = strlen(s2); for (int i = 0; i < len2; i++) { int get = 0, win = 1; for (int j = 0; j < len1; j++) { if (s1[j] == s2[i]) { get = 1; s1[j] = '-'; }//猜对的字符变成'-' if (s1[j] != '-')win = 0; } if (win) { printf("You win.\n"); return; } if (!get)left--; if (!left) { printf("You lose.\n"); return; } } printf("You chickened out.\n"); } int main(void) { int kase; char s1[10000], s2[10000]; while (~scanf("%d", &kase) && kase != -1) { scanf("%s%s", s1, s2); printf("Round %d\n", kase); solve(s1, s2); } return 0; }
作者:Barsaker



judge 手游

需要 登录 后方可回复, 如果你还没有账号请 注册新账号