取火柴

#include<cstdio>

int main()
{
    int c,p,spare=21;
    printf("你能战胜我吗?\n");
    while(1)
    {
        printf("还有%d根火柴\n",spare);
        printf("People:");
        scanf("%d",&p);
        if(p<1||p>4||p>spare)
        {
            printf("违规\n");
            continue;
        }
        spare=spare-p;
        if(spare==0)
        {
            printf("computer win!\n");
            break;
        }
        c=5-p;
        spare-=c;
        printf("Computer:%d\n",c);
        if(spare==0)
        {
            printf("people win!\n");
            break;
        }
    }
    return 0;

}

你可能感兴趣的:(取火柴)