赞
踩
样例输入:
1 c
heese
chese
2cheese
abcdefg
3 c
heese
abcdefgij
-1
样例输出:
Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.
- #include <stdio.h>
- #include <string.h>
- #define maxn 100
- int left, chance; //left记录还有几个单词要猜测,错几次机会就要输了
- char s1[maxn], s2[maxn];
- int win, lose; //win=1表示赢了,lose=1,表示输了
-
- void guess(char ch) {
- int bad = 1; //默认猜错了
- for(int i = 0; i < strlen(s1); i++)
- if(ch == s1[i]) { //表示猜对了,把已经猜对了的,置为空格,防止下次又猜到了,又判对
- s1[i] = ' ';
- bad = 0;
- left--; //猜测的单词减少
- }
- if(bad) --chance;
- if(!chance) lose = 1; //没有机会就表示输了
- if(!left) win = 1; //单词已猜完
- }
-
- int main()
- {
- int rnd;
- while(scanf("%d%s%s", &rnd, s1, s2) == 3 && rnd != -1) {
- printf("Round %d\n", rnd);
- win = lose = 0;
- chance = 7; //求解每组数据之前初始化
- left = strlen(s1);
- 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;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。