PAT Basic 1071. 小赌怡情(15)

0
0
0
1. 云栖社区>
2. 博客>
3. 正文

PAT Basic 1071. 小赌怡情(15)

lovedan 2017-11-08 15:40:00 浏览476

题目内容

n1 b t n2

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

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

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

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

简评

1.“输出格式”中的两句话之间的空格数，和“输出样例”中不一样。后者是2个。题目提交需要按照2个空格来。
2."Game Over."这句话目测是不在测试用例中的。输出"Game Over."后，是否输出换行符，都不影响评测结果。

AC代码

``````#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;

int main() {
int T, K;
cin >> T >> K;
int n1, b, t, n2;
for (int i = 0; i < K; i++) {
cin >> n1 >> b >> t >> n2;

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);
}
if (T == 0) {
printf("Game Over.\n");
return 0;
}
}

return 0;
}``````

lovedan
+ 关注

corcosa 14734人浏览