小陈挑战搭建地月电梯,在资本家算计下能否成功?
```cpp #include <iostream> #include <iomanip> using namespace std; int main() { double n, a; cin >> n >> a; double totalCost = 0; // 小陈花掉的钱 double borrowed = 0; // 资本家借给小陈的钱 double interest = 0; // 最终产生的利息 double distance = 384400; // 地球到月球的距离 double costPer100km = 5; // 每100千米的花费 double timePer100km = 1; // 每100千米的耗时 double currentDistance = 0; // 当前已搭建的距离 double currentMonth = 0; // 当前月份 while (currentDistance < distance) { // 月初检查是否有足够的钱支付5万元 if (n >= 5) { n -= 5; totalCost += 5; } else { double need = 5 - n; borrowed += need; n = 0; } // 搭建100千米 currentDistance += 100; currentMonth += 1; // 月底资产增加 n += a; // 计算利息 interest += borrowed * 0.1; borrowed *= 1.1; // 检查是否破产 if (borrowed > 5) { cout << fixed << setprecision(3) << totalCost << " " << borrowed << " " << interest << endl; return 0; } } cout << fixed << setprecision(3) << totalCost << " " << borrowed << " " << interest << endl; return 0; } ``` 需要注意的逻辑点: 1. 利息计算:每个月借的钱会增加10%的利息,因此需要在每个月结束时更新借的钱和利息。 2. 破产条件:如果借的钱超过5万元,小陈就会破产,程序需要立即输出结果并结束。 3. 资产增加:小陈的资产每个月月底会增加a万元,这部分钱不能用于当月的消费。 ######[AI写代码神器 | 457点数解答 | 2025-02-12 08:55:21]
- 详解银行账户管理代码:开户、存款与取款功能实现(讯飞星火 | 195点数解答 | 2024-08-08 14:53:52)312
- 超详细!逐行解读银行账户管理代码的含义、作用与用法(讯飞星火 | 152点数解答 | 2024-08-08 14:58:48)330
- C语言:银行账户结构体与操作函数的代码解析及使用示例(讯飞星火 | 298点数解答 | 2024-08-08 15:01:11)309
- 代码揭秘:bankaccount *account 的含义与功能解析( | 124点数解答 | 2024-08-08 15:12:48)348
- C 语言揭秘:`bankaccount *account` 与 `account->balance += amount` 的原理及作用 ( | 161点数解答 | 2024-08-08 15:18:14)323
- 代码解析:指针与结构体在银行账户系统中的作用与好处( | 201点数解答 | 2024-08-08 15:39:09)292
- 深度解析:`bankaccount *account` 与 `bankaccount account` 在代码中的差异( | 174点数解答 | 2024-08-08 15:43:13)314
- 揭秘:为何 bankaccounttest 函数用 bankaccount account 而非 bankaccount *account? (字节豆包 | 218点数解答 | 2024-08-08 15:48:26)432
- 解惑:为何deposit函数printf无&,另一函数却有?代码奥秘大揭秘! (字节豆包 | 132点数解答 | 2024-08-08 15:53:07)285
- 揭秘:为何printf中getbalance函数传参的account前要加&? (字节豆包 | 121点数解答 | 2024-08-08 15:56:21)333
- C 语言揭秘:openaccount、deposit、withdraw 函数中 account 前加 & 的原因 (字节豆包 | 142点数解答 | 2024-08-08 16:03:25)331
- 工程师必知!8大策略克服API挑战 (百度文心 | 373点数解答 | 2023-11-09 18:34:35)187