PTA 乙级 1071 小赌怡情 (15分) C++
水水水!
1 #include<iostream> 2 3 using namespace std; 4 5 int main() { 6 int allt = 0, k = 0; 7 cin >> allt >> k; 8 for (int i = 0; i < k; ++i) { 9 int n1 = 0, n2 = 0; 10 int b = 0, t = 0; 11 cin >> n1 >> b >> t >> n2; 12 if (allt >= t) { //筹码数大于赌注数 13 if ((n1 > n2) != b) { 14 allt += t; 15 printf("Win %d! Total = %d.\n", t, allt); 16 } 17 else { 18 allt -= t; 19 printf("Lose %d. Total = %d.\n", t, allt); 20 } 21 } 22 else 23 printf("Not enough tokens. Total = %d.\n", allt); 24 if (allt == 0) { cout << "Game Over."; return 0; } //筹码为零,输出后直接退出 25 } 26 return 0; 27 }
默默地一点点变强,细节决定成败