您的位置:首页 > 其它

489 - Hangman Judge

2016-01-27 21:02 239 查看
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=430&mosmsg=Submission+received+with+ID+16764260

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int left, chance;
int win, lost;
char ans[101], in[101];

void guess(char c);

int main() {
int T = 0, i = 0;
while (scanf("%d%s%s", &T, ans, in) == 3 && T != -1) {
win = lost = 0;
chance  = 7;
left = strlen(ans);
for (i = 0; i < strlen(in); i++) {
guess(in[i]);
if (win || lost) break;
}
printf("Round %d\n", T);
if (win)
printf("You win.\n");
else if (lost)
printf("You lose.\n");
else
printf("You chickened out.\n");
}
return 0;
}

void guess(char c) {
int i = 0, found = 0;
for (i = 0; i < strlen(ans); i++) {
if (c == ans[i]) {
ans[i] = ' ';
found = 1;
left--;
}
}
if (!found) chance--;
if (!left) {
win = 1;
return;
} else if (!chance) {
lost = 1;
return;
}
return;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: