PAT 1071. Small Bet (JAVA)

Source: Internet
Author: User

1071. Small bets (15) time limit: Ms Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Chen, Yue

As the saying goes, "small bet on Love." This is a very simple mini-game: First the computer gives the first integer, then the player bets bet the second integer will be larger or smaller than the first number, the player bets T chips, the computer gives a second number. If the player guesses the right, the system rewards the player T chips, otherwise the player T chips are deducted.

Note: Players can bet no more than the number of chips they have on their account. When the player loses all the chips, the game ends.

Input format:

The input gives 2 positive integers t and K (<=100) in the first line, respectively, the number of chips that the system gives to the player in its initial state, and the number of games that need to be processed. Then K line, each row corresponds to a game, the order gives 4 numbers:

N1 B t N2

where N1 and n2 are integers in the computer's two [0, 9], guaranteeing that two numbers are unequal. b is 0 means the player bets "small", for 1 means the player bet "big". T indicates the number of chips the player bets, guaranteed to be within the integer range.

Output format:

For each game, the output is based on the following conditions (where T is the player's bet amount and X is the amount of chips the player currently holds):

    • Player wins, output
      Win t!  Total = x.
    • Player lose, output
      Lose T.  Total = x.
    • Player bets over the amount of chips held, output
      Not enough tokens.  Total = x.
    • After the player has gambled, the output
      Game over.
      and end the program.
Input Sample 1:
100 48 0 100 23 1 50 15 1 200 67 0 200 8
Output Example 1:
Win 100!  Total = 200.Lose.  Total = 150.Not enough tokens.  Total = 150.Not enough tokens.  Total = 150.
Input Sample 2:
100 48 0 100 23 1 200 15 1 200 67 0 200 8
Output Example 2:
Win 100!  Total = 200.Lose.  Total = 0.Game over.
Note: You need to determine whether the game is over after you win or lose. Or there's going to be a test point.
1 ImportJava.util.Scanner;2 3 4  Public classMain1071 {5      Public Static voidMain (string[] args) {6         intt,k;7Scanner sc =NewScanner (system.in);8T =sc.nextint ();9K =sc.nextint ();Ten          One          for(inti=0;i<k;i++){ A             intn1,b,t,n2; -N1 =sc.nextint (); -b =sc.nextint (); thet =sc.nextint (); -N2 =sc.nextint (); -              -             if(t>T) { +System.out.println ("Not enough tokens. Total = "+t+". "); -                  +}Else{ A                 if(n1>n2) { at                     if(b==0){ -T = t+T; -System.out.println ("Win" +t+ "! Total = "+t+". "); -                     } -                     if(b==1){ -t = tT; inSystem.out.println ("Lose" +t+ ". Total = "+t+". "); -                     } to                 } +                 if(n1<n2) { -                     if(b==1){ theT = t+T; *System.out.println ("Win" +t+ "! Total = "+t+". "); $                     }Panax Notoginseng                     if(b==0){ -t = tT; theSystem.out.println ("Lose" +t+ ". Total = "+t+". "); +                     } A                 } the             } +             if(t==0){ -System.out.println ("Game over."); $                  Break; $             } -         } -          the     } - Wuyi}

PAT 1071. Small Bet (JAVA)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.