1 条题解

  • 0
    @ 2048-5-5 18:56:16

    练7.3买图书

    解题思路

    打八折后的书价是 0.8m,剩余钱为 n-0.8m。

    正确性说明

    现有钱减去实际支付金额即为余额。

    易错点

    八折是支付 80%,不是减去 80%;输出两位小数。

    复杂度

    本题规模固定,时间 O(1),额外空间 O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        double n, m;
        cin >> n >> m;
        cout << fixed << setprecision(2) << n - m * 0.8 << "\n";
        return 0;
    }
    
    • 1