top1编程
← 返回题目
题解

【入门】行李托运价格

1 条题解

  • 0
    @ 2026-7-30 1:07:25

    解题思路

    重量不超过 10 千克时收费 2.5 元;超过 10 千克时,每多 1 千克加 1.5 元。根据重量分情况计算即可。

    参考代码

    
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main() {
        // 读入题目给出的输入数据
        int n;
        cin >> n;
        double s;
        if (n <= 10) s = 2.5;
        else s = 2.5 + (n - 10) * 1.5;
        // 完成题目的关键计算或判断
        cout << fixed << setprecision(2) << s;
        // 输出题目要求的答案
        return 0;
    }
    

    复杂度

    时间复杂度 O(1),空间复杂度 O(1)

    • 1