A109.津津的储蓄计划 题解
2026-07-16 14:42:42
发布于:广东
27阅读
0回复
0点赞
先评价,津津一个月的零花钱好多啊,是我的15倍呢!!!
C++版:
#include <iostream>
using namespace std;
int main(){
int cash = 0; // 自己手上现金
int save = 0; // 存在妈妈那里的钱
int budget;
for (int month = 1; month <= 12; month++){
cin >> budget;
cash += 300; // 月初收到300
if (cash < budget){ // 不够花
cout << -month << endl;
return 0;
}
cash -= budget; // 花掉预算
if (cash >= 100){
save += cash / 100 * 100;
cash %= 100;
}
}
// 全部月份顺利度过
int ans = save * 1.2 + cash;
cout << ans << endl;
return 0;
}
Python版:
cash = 0
save = 0
for month in range(1, 13):
budget = int(input())
cash += 300
if cash < budget:
print(-month)
exit()
cash -= budget
if cash >= 100:
save += cash // 100 * 100
cash %= 100
res = int(save * 1.2 + cash)
print(res)
大家加油,我试过了,可以通过的!



这里空空如也



有帮助,赞一个