题意:给你一个单词,让你猜,第二行为猜测的单词,规则是,比如单词是book,你猜测的o,则book中的oo均猜对,有7次机会,每猜错一个字母,chance–,若这七次机会用完还没有猜对,则lose,若在机会用完之前才对了,则win,若既没输也没赢则chickened out。
#include<stdio.h>
#include<string.h>
int main()
{
int n;
while(scanf("%d", &n) && n!=-1){
char str1[1000], str2[1000];
scanf("%s %s", str1, str2);
int len1 = strlen(str1);
int len2 = strlen(str2);
int chance = 7, left = len1, win = 0, lose = 0;
for(int i = 0; i < len2; i++){
int flag = 1;
for(int j = 0; j < len1; j++){
if(str2[i] == str1[j]){
str1[j] = ' '; //猜对的单词全变为空格
left--;
flag = 0;
}
}
if(flag)
chance--;
if(!chance)
lose = 1;
if(!left)
win = 1;
if(lose || win)
break;
}
if(win)
printf("Round %d\nYou win.\n", n);
else if(lose)
printf("Round %d\nYou lose.\n", n);
else
printf("Round %d\nYou chickened out.\n", n);
}
return 0;
}