题目链接:https://vjudge.net/problem/UVA-489
题目描述:
参考代码:
#include <stdio.h>
#include <string.h>
#define MAXSIZE 100
int left,chance;//还需要猜left个位置,错chance次之后就为输
char s[MAXSIZE],s2[MAXSIZE];
int win,lose;//win=1表示已经赢了,lose等于1i表示已经输了
void guess(char ch) {
int bad = 1;//作一个标记
for(int i = 0; i < strlen(s); i++)
if(s[i]==ch) {
left--;
s[i] = ' ';
bad = 0;
}
if(bad) --chance;
if(!chance) lose = 1;
if(!left) win = 1;
}
/*主函数*/
int main() {
int Round;
while(scanf("%d%s%s",&Round,s,s2)==3 && Round!=-1) {
printf("Round %d\n",Round);
win = lose = 0;//初始化
left = strlen(s);
chance = 7;
for(int i = 0; i < strlen(s2); i++) {
guess(s2[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;
}