您的位置:首页 > 其它

PAT (Basic Level) Practise (中文)1071. 小赌怡情(15)

2017-10-12 17:09 471 查看
小赌怡情(15)

时间限制

400 ms

内存限制

65536 kB

代码长度限制

8000 B

判题程序

Standard

作者

CHEN, Yue

常言道“小赌怡情”。这是一个很简单的小游戏:首先由计算机给出第一个整数;然后玩家下注赌第二个整数将会比第一个数大还是小;玩家下注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.



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String s=bf.readLine();
int chouma=Integer.parseInt(s.split(" ")[0]);
int time=Integer.parseInt(s.split(" ")[1]);
String[] str=new Str
4000
ing[time];
for (int i = 0; i < str.length; i++) {
str[i]=bf.readLine();
}
for (int i = 0; i < time; i++) {
int temp[]=new int[4];
temp[0]=Integer.parseInt(str[i].split(" ")[0]);
temp[1]=Integer.parseInt(str[i].split(" ")[1]);
temp[2]=Integer.parseInt(str[i].split(" ")[2]);
temp[3]=Integer.parseInt(str[i].split(" ")[3]);
if (chouma>0) {

if (temp[2]<=chouma) {

if (temp[0]<temp[3]&&temp[1]==1) {
chouma+=temp[2];
System.out.println("Win "+temp[2]+"!  Total = "+chouma+".");
}else if (temp[0]>temp[3]&&temp[1]==0) {
chouma+=temp[2];
System.out.println("Win "+temp[2]+"!  Total = "+chouma+".");
}else if (temp[0]<temp[3]&&temp[1]==0) {
chouma-=temp[2];

System.out.println("Lose "+temp[2]+".  Total = "+chouma+".");

}else if (temp[0]>temp[3]&&temp[1]==1) {
chouma-=temp[2];

System.out.println("Lose "+temp[2]+".  Total = "+chouma+".");

}
}else {
System.out.println("Not enough tokens.  Total = "+chouma+".");
}
}else {
System.out.println("Game Over.");
return;
}
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: