Click on the link full solution summary PAT B -AC
Title:
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 format:
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
an integer in the given computer has two [0, 9], to ensure the two numbers are not equal. b
0 means the players bet small, 1 means the players bet big. t
It represents the number of player bets chips, to ensure that within the integer range.
Output format:
for every game, the corresponding output of the following circumstances (where t is the player bet amount, x is the amount of chips currently held by the player):
Players win, output Win t! Total = x.
;
the player loses, output Lose t. Total = x.
;
players bet more than the amount of chips held by the output Not enough tokens. Total = x.
;
the player gambled output Game Over.
and the program ends.
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.
My code:
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<sstream>
using namespace std;
//有的时候题目是一起做的,所以会有不需要的头文件
int main()
{
int remain=0,K=0;
cin>>remain>>K;
for(int i=0;i<K;i++)
{
int a,guess,reward,b;
cin>>a>>guess>>reward>>b;
if(remain<=0)
{
cout<<"Game Over."<<endl;
return 0;
}
else if(remain<reward)
{
printf("Not enough tokens. Total = %d.\n",remain);
}
else if((a>b&&guess==0) || (a<b&&guess==1))
{
remain+=reward;
printf("Win %d! Total = %d.\n",reward,remain);
}
else
{
remain-=reward;
printf("Lose %d. Total = %d.\n",reward,remain);
}
}
return 0;
}