PAT 1071. 小赌怡情

PAT 1071. 小赌怡情

常言道“小赌怡情”。这是一个很简单的小游戏:首先由计算机给出第一个整数;然后玩家下注赌第二个整数将会比第一个数大还是小;玩家下注t个筹码后,计算机给出第二个数。若玩家猜对了,则系统奖励玩家t个筹码;否则扣除玩家t个筹码。

注意:玩家下注的筹码数不能超过自己帐户上拥有的筹码数。当玩家输光了全部筹码后,游戏就结束。

输入格式:

输入在第一行给出2个正整数T和K(<=100),分别是系统在初始状态下赠送给玩家的筹码数、以及需要处理的游戏次数。随后K行,每行对应一次游戏,顺序给出4个数字:

n1 b t n2

其中n1和n2是计算机先后给出的两个[0, 9]内的整数,保证两个数字不相等。b为0表示玩家赌“小”,为1表示玩家赌“大”。t表示玩家下注的筹码数,保证在整型范围内。

输出格式:

对每一次游戏,根据下列情况对应输出(其中t是玩家下注量,x是玩家当前持有的筹码量):

玩家赢,输出“Win t! Total = x.”;
玩家输,输出“Lose t. Total = x.”;
玩家下注超过持有的筹码量,输出“Not enough tokens. Total = x.”;
玩家输光后,输出“Game Over.”并结束程序。
输入样例1:

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

输出样例1:

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

输入样例2:

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

输出样例2:

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

代码如下

#include<iostream>
using namespace std;
int main(){
    int total,times,n1,b,t,n2,temp;
    cin>>total>>times;
    for(int i=0;i<times;i++){
        cin>>n1>>b>>t>>n2;
        if(t<=total){
            temp=n2>n1?1:0;
            if(temp==b){
            total+=t;
            printf("Win %d!  Total = %d.\n", t, total);
            }
            else{
            total-=t;
            printf("Lose %d.  Total = %d.\n", t, total);
            }
        }else
        printf("Not enough tokens.  Total = %d.\n", total);
        if(total==0){
        printf("Game Over.\n");
        break;
        }
    }
    return 0;
} 

原文地址:https://www.cnblogs.com/A-Little-Nut/p/8145160.html

时间: 2024-08-14 17:01:17

PAT 1071. 小赌怡情的相关文章

PAT 乙级 1071.小赌怡情 C++/JAVA

题目来源 常言道“小赌怡情”.这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注 t 个筹码后,计算机给出第二个数.若玩家猜对了,则系统奖励玩家 t 个筹码:否则扣除玩家 t 个筹码. 注意:玩家下注的筹码数不能超过自己帐户上拥有的筹码数.当玩家输光了全部筹码后,游戏就结束. 输入格式: 输入在第一行给出 2 个正整数 T 和 K(≤ 100),分别是系统在初始状态下赠送给玩家的筹码数.以及需要处理的游戏次数.随后 K 行,每行对应一次游

PAT 1071 Speech Patterns[一般]

1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker's iden

PAT 1071. Speech Patterns (25)

1071. Speech Patterns (25) People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker's ident

1071. 小赌怡情(15)

常言道“小赌怡情”.这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注t个筹码后,计算机给出第二个数.若玩家猜对了,则系统奖励玩家t个筹码:否则扣除玩家t个筹码. 注意:玩家下注的筹码数不能超过自己帐户上拥有的筹码数.当玩家输光了全部筹码后,游戏就结束. 输入格式: 输入在第一行给出2个正整数T和K(<=100),分别是系统在初始状态下赠送给玩家的筹码数.以及需要处理的游戏次数.随后K行,每行对应一次游戏,顺序给出4个数字: n1 b t

1071 小赌怡情 (15分)

常言道“小赌怡情”.这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注 t 个筹码后,计算机给出第二个数.若玩家猜对了,则系统奖励玩家 t 个筹码:否则扣除玩家 t 个筹码. 注意:玩家下注的筹码数不能超过自己帐户上拥有的筹码数.当玩家输光了全部筹码后,游戏就结束. 输入格式: 输入在第一行给出 2 个正整数 T 和 K(≤ 100),分别是系统在初始状态下赠送给玩家的筹码数.以及需要处理的游戏次数.随后 K 行,每行对应一次游戏,顺序给

PAT 1071. Speech Patterns

又是考输入输出 #include <cstdio> #include <cstdlib> #include <string> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; char buf[1048577]; bool is_alphanumerical(char &ch) { if (ch >=

1071 小赌怡情

题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805264312549376 题解: 1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 int T, K, n1, b, t, n2; 6 cin >> T >> K; 7 while (K--) { 8 cin >> n1 >> b &

PAT:1071. Speech Patterns (25) AC

#include<ctype.h> #include<iostream> #include<map> #include<string> using namespace std; bool check(char a) //判断是否为有效字符 { if(isdigit(a) || isalpha(a)) return true; return false; } int main() { map<string,int> count; //单词与次数的映

PAT (Advanced Level) 1071. Speech Patterns (25)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std;