PAT Basic 1071 flutter cheer (15 points)

As the saying goes "flutter cheer." This is a very simple game: first by computer is given first integer; then the players will be betting on the second integer number larger than the first or small; t after the player bets chips, the computer gives the second number. If the player guessed it, the system rewards the player t chips; otherwise deducted from the player t credits.

Note: The number of chips a player can not bet more than a few chips have their own account. When the player gambled all the chips, the game is over.

Input formats:

In the first line of the input is given two positive integers T and K ( ≤ 100), respectively, the number of games in the initial state of the system presented to a number of chips of the players, and need to be addressed. Then K rows, each row corresponds to one game, four numbers in the order given:

n1 b t n2

Wherein  n1 and  n2 an integer in the given computer has two [0, 9], to ensure the two numbers are not equal. b 0 means the player bet , 1 indicates the player bet . t It represents the number of player bets chips, to ensure that within the integer range.

Output formats:

For every game, according to the following conditions correspond to the output (which  t is the amount the player bets, x is the amount of chips the player currently held):

  • Players win, output  Win t! Total = x.;
  • Player input, an output  Lose t. Total = x.;
  • Players bet more than the amount of chips held by the output  Not enough tokens. Total = x.;
  • After the players gambled, output  Game Over. and end the program.

Sample Input 1:

100 4
8 0 100 2
3 1 50 1
5 1 200 6
7 0 200 8

Output Sample 1:

Win 100!  Total = 200.
Lose 50.  Total = 150.
Not enough tokens.  Total = 150.
Not enough tokens.  Total = 150.

Sample Input 2:

100 4
8 0 100 2
3 1 200 1
5 1 200 6
7 0 200 8

Output Sample 2:

Win 100!  Total = 200.
Lose 200.  Total = 0.
Game Over.


#include <iostream>
using namespace std;
int main(){
    int M,N,n1,b,t,n2;
    cin>>M>>N;
    while(N--){
        cin>>n1>>b>>t>>n2;
        if(b==1){
            int tmp=n1;
            by n1 = N2;
            n2=tmp;
        }
        if(M-t<0){
            cout<<"Not enough tokens.  Total = "<<M<<"."<<endl;
            continue;
        }
        if(n2<n1) {
            M+=t;
            cout<<"Win "<<t<<"!  Total = "<<M<<"."<<endl;
        }else{
            M-=t;
            cout<<"Lose "<<t<<".  Total = "<<M<<"."<<endl;
            if(M==0){
                cout<<"Game Over."<<endl;
                system("pause");
                return 0;
            }
        }
    }
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11361529.html