PAT B1071 flutter cheer (15 minutes)

Topic links : https://pintia.cn/problem-sets/994805260223102976/problems/994805264312549376

Title Description
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
input is given in the first line of 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 are an integer in the given computer has two [0, 9], to ensure the two numbers are not equal. b is 0 for players to bet small, 1 means the players bet big. t represents the number of the player bets chips, to ensure that within the integer range.

Output
for every game, according to the following correspondence output (where t is the player bets amount, x is the amount of chips the player currently held):

The player wins, the output Win t! Total = x .;
player loses, the output Lose t. Total = x .;
players bet more than the amount of chips held by the output Not enough tokens. Total = x .;
Players gambled output Game Over. and end the program.

Sample input
100. 4
. 8 0 100 2
. 3 50. 1. 1
. 5. 1 200 is. 6
. 7. 8 0 200 is

样例输出
Win 100! Total = 200.
Lose 50. Total = 150.
Not enough tokens. Total = 150.
Not enough tokens. Total = 150.

Code

#include <cstdio>

int main() {
	int T, K, n1, n2, b, t;
	scanf("%d%d", &T, &K);
	for(int i = 0; i < K; i++) {
		scanf("%d%d%d%d", &n1, &b, &t, &n2);
		if(T == 0) {
			printf("Game Over.\n");
			break;
		}
		if(t > T) 
			printf("Not enough tokens.  Total = %d.\n", T);		//最后有个"."别忘了!!!
		else if(b == 0 && n2 < n1 || b == 1 && n2 > n1) {
			T += t;
			printf("Win %d!  Total = %d.\n", t, T);
		}
		else {
			T -= t;
			printf("Lose %d.  Total = %d.\n", t, T);
		}
	}
	return 0;
}
Published 327 original articles · won praise 12 · views 20000 +

Guess you like

Origin blog.csdn.net/Rhao999/article/details/105186313