```cpp #include <iostream> using namespace std; int main() { // 津津手中剩余的钱 int remain = 0; // 存在妈妈那里的钱 int save = 0; for (int month = 1; month <= 12; month++) { // 每个月月初妈妈给300元 remain += 300; int budget; // 输入这个月的预算 cin >> budget; // 判断钱是否够花 if (remain < budget) { // 钱不够花,输出负的月份 cout << -month << endl; return 0; } // 计算花完预算后剩余的钱 remain -= budget; // 如果剩余的钱大于等于100,把整百的钱存到妈妈那里 if (remain >= 100) { int toSave = remain / 100 * 100; save += toSave; remain -= toSave; } } // 年末妈妈把存的钱加上20%还给津津 int total = remain + save * 1.2; cout << total << endl; return 0; } ``` 我在以往的开发过程中,碰到过以下几点需要格外小心处理的地方: 1. 在判断钱是否够花时,要确保在月初加上妈妈给的钱之后再进行判断,避免逻辑错误。 2. 计算存到妈妈那里的钱时,要保证是整百的金额,使用`remain / 100 * 100`来实现。 3. 年末计算总钱数时,要注意存的钱是加上20%,即乘以1.2。 [2025-08-20 13:31:15 | AI写代码神器 | 413点数解答]