You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.8 KiB

2 years ago
#include <bits/stdc++.h>
#define maxn 100
int left, chance; //还需要猜left个位置,错chance次之后就会输
char s[maxn], s2[maxn]; //答案是字符串s,玩家猜的字母序列是s2
bool win, lose; //win=1表示已经赢了;lose=1表示已经输了
/**
*
* @param ch
*/
void guess(char ch) {
bool bad = true;
for (int i = 0; i < strlen(s); i++)
if (s[i] == ch) {
left--;
s[i] = ' '; //阅后即焚~,标识为空格
bad = false;
}
if (bad) --chance; //错一次,机会减少一次
if (!chance) lose = true; //没有机会了,就是输了
if (!left) win = true;
}
int main() {
int rnd; //轮次 一级公民在scanf中使用需要使用&符,表示按地址引用。
// s和s2为字符串数组二级公民不需要使用&符!
/*
scanf("%d %d",&a,&b) ab2
ab1
end of fileEOF
*/
while (scanf("%d%s%s", &rnd, s, s2) == 3 && rnd != -1) //rnd=-1表示输入-1就停止
{
printf("Round %d\n", rnd);
win = lose = false; //求解一组新数据之前要初始化
//测长
left = strlen(s);
//机会有7次
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;
}