1 条题解

  • 0
    @ 2025-11-30 16:26:51

    C++ :

    #include <iostream>
    using namespace std;
    int main() {
        int balance = 100; // 初始存款
        int target=200;        // 目标金额
        int save_amount=50;   // 每周存款金额
        int withdraw_amount=20; // 每周取款金额
        int weeks = 0;     // 存钱的周数
        while (balance < target) {
            balance += save_amount;  // 每周存钱
            weeks++;
            balance -= withdraw_amount; // 每周取钱
        }
        cout << weeks;
        return 0;
    }
    
    • 1

    T1-7-E4 小明的存钱计划(循环结构 - while)

    信息

    ID
    1370
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者