problemscpp
A collection of my answers to algorithm problems in c++.
函数
pat::b::b1071 命名空间参考

1071 小赌怡情 更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (b1071, case1)
 
 TEST (b1071, case2)
 

详细描述

1071 小赌怡情

函数说明

◆ main()

int pat::b::b1071::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp2445 行定义.

2445 {
2446 int t;
2447 int k;
2448 cin >> t >> k;
2449 while(k-- != 0) {
2450 int n1;
2451 int b;
2452 int tt;
2453 int n2;
2454 cin >> n1 >> b >> tt >> n2;
2455 if(tt > t) {
2456 cout << "Not enough tokens. Total = " << t << '.' << endl;
2457 continue;
2458 }
2459 if(static_cast<int>(n2 > n1) == b) {
2460 t += tt;
2461 cout << "Win " << tt << "! Total = " << t << '.' << endl;
2462 } else {
2463 t -= tt;
2464 cout << "Lose " << tt << ". Total = " << t << '.' << endl;
2465 }
2466 if(t == 0) {
2467 cout << "Game Over.";
2468 return 0;
2469 }
2470 }
2471 return 0;
2472 }

被这些函数引用 TEST().

◆ TEST() [1/2]

pat::b::b1071::TEST ( b1071  ,
case1   
)

在文件 pat_test.cpp1140 行定义.

1140 {
1141 istringstream in("100 4\n"
1142 "8 0 100 2\n"
1143 "3 1 50 1\n"
1144 "5 1 200 6\n"
1145 "7 0 200 8");
1146 auto out = ostringstream();
1147 main(in, out);
1148 const auto ans = out.str();
1149 ASSERT_EQ("Win 100! Total = 200.\n"
1150 "Lose 50. Total = 150.\n"
1151 "Not enough tokens. Total = 150.\n"
1152 "Not enough tokens. Total = 150.\n",
1153 out.str());
1154 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

pat::b::b1071::TEST ( b1071  ,
case2   
)

在文件 pat_test.cpp1156 行定义.

1156 {
1157 istringstream in("100 4\n"
1158 "8 0 100 2\n"
1159 "3 1 200 1\n"
1160 "5 1 200 6\n"
1161 "7 0 200 8");
1162 auto out = ostringstream();
1163 main(in, out);
1164 const auto ans = out.str();
1165 ASSERT_EQ("Win 100! Total = 200.\n"
1166 "Lose 200. Total = 0.\n"
1167 "Game Over.",
1168 out.str());
1169 }

引用了 main().