刽子手游戏

 

样例输入:

1

cheese

chese

2

cheese

abcdefg

3

cheese

abcdefgij

-1

样例输出:

Round1

You win.

Round 2

You chickened out.

Round 3

You lose.

 

#include<stdio.h>
#include<string.h>
int chance;
char TR[50],YR[50];
int lose, win;
int left;

void guess(char ch)
{
    int bad = 1;
    for (int i = 0; i < strlen(TR); i++)
    {
        if(ch == TR[i])
            {
                TR[i] == ' ';
                left--;
                bad = 0;
            }
    }
    if (bad)
        chance--;
    if (!chance)
        lose = 1;
    if (!left)
        win = 1;
    
}

int main(void)
{
    int rnd,quit =1;



    
    while (scanf("%d%s%s", &rnd, &TR, &YR) == 3 && rnd != -1)
    {
        printf("Round%d\n", rnd);
        lose = 0; win = 0;
        chance = 7;
        left = strlen(TR);
        for (int i = 0; i < strlen(YR); i++)
        {
            quit = 0;
            guess(YR[i]);

            if (lose == 1 || win == 1)
                break;
        }
        if (lose == 1)
            printf("You lose");
        else if (win)
            printf("You win");
        else
            printf("You chickened  out");
    }

}

 

posted @ 2020-12-16 19:03  loliconsk  阅读(62)  评论(0)    收藏  举报