我的代码如下,有点冗长,希望谅解!
代码如下:
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <set>
using namespace std;
// Get 300 yuan each month
int main() {
int save = 0; // Save by mum
int death_month = 0; // The month which die
int money = 0; // Money in hands
int use = 0; // Will/Already used
for (int i = 0; i < 12; i++) {
money += 300;
cin >> use;
money -= use;
if (money < 0) {
death_month = i;
cout << death_month << endl;
break;
}
else {
save += money / 100;
money %= 100;
}
while (i == 12) {
if (save = 0) {
cout << money << endl;
break;
}
else {
money += save * 20 + save * 100 + save * 100;
cout << money << endl;
break;
}
}
}
return 0;
}
谢谢解答!!!