题解
2025-11-08 19:40:42
发布于:广东
5阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main() {
int cash = 0; // 手上的零钱
int save = 0; // 存在妈妈那里的总额(整百)
for (int month = 1; month <= 12; month++) {
int budget;
cin >> budget;
// 月初拿到300元
cash += 300;
// 检查是否够花
if (cash < budget) {
cout << '-' << month << endl;
return 0;
}
// 花掉预算
cash -= budget;
// 判断是否可以存整百(月末剩余 >= 100)
if (cash >= 100) {
int deposit = (cash / 100) * 100; // 取整百
save += deposit;
cash -= deposit; // 把整百部分存走,留下零头
}
// 注意:这里不需要额外检查 cash < 0,前面已保证
}
// 年末妈妈返还:本金 + 20%
// 因为 save 是 100 的倍数,所以 save * 1.2 一定是整数
// 推荐使用整数运算避免浮点风险
int bonus = save + save / 5; // 相当于 save * 1.2
cout << cash + bonus << endl;
return 0;
}
点个赞吧,球球了
这里空空如也



有帮助,赞一个