小赌怡情

题源

PTA 乙级

题解

#include<stdio.h>
int T,K;
int n1,b,t,n2;
int main(){
    scanf("%d %d",&T,&K);
    int i = 0;
    for(i = 0;i < K;i++){
        scanf("%d %d %d %d",&n1,&b,&t,&n2);
        if(t>T){printf("Not enough tokens.  Total = %d.\n",T);continue;}
        else{
            if((n1>n2 && b==0)||(n1<n2 && b==1)){
                T += t;
                printf("Win %d!  Total = %d.\n",t,T);
                continue;
            }
            else{
                T -= t;
                printf("Lose %d.  Total = %d.\n",t,T);
                if(T<=0){printf("Game Over.\n");return 0;}
            }
        }
    }
    return 0;
}
上一篇:PAT (Basic Level) Practice (中文)1071 小赌怡情 (15 分)


下一篇:浅谈时间复杂度