提交时间:2026-01-04 14:57:26

运行 ID: 80052

#include <iostream> using namespace std; int main() { int budget; // 每月预算 int cash = 0; // 津津手中剩余的零钱(不足100的部分) int saved = 0; // 存在妈妈那里的整百存款总额 for (int month = 1; month <= 12; month++) { cin >> budget; // 读入本月预算 // 1. 月初:收到300元,加上上月结余 cash += 300; // 2. 减去本月预算 cash -= budget; // 3. 检查是否透支 if (cash < 0) { // 钱不够用,输出负的月份 cout << -month << endl; return 0; // 程序直接结束 } // 4. 如果剩余钱大于等于100,存整百部分 if (cash >= 100) { int hundreds = cash / 100; // 计算可以存多少个100元 saved += hundreds * 100; // 整百部分存入妈妈那里 cash -= hundreds * 100; // 手中只保留零头 // 等价于:cash %= 100; } // 否则,cash保持不变(小于100元,不储蓄) } // 5. 顺利度过12个月,计算年末总额 // 存款加上20%利息,然后加上手中零钱 double total = saved * 1.2 + cash; // 输出整数(题目样例为整数,直接强制转换或四舍五入) cout << (int)total << endl; // 或使用 cout << int(total + 0.5) 四舍五入 return 0; }