全部评论 1

  • AC🐶推荐最优解:

    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main() {
        long long total_cents = 0; // 单位:分(即 0.01 元)
        for (int i = 0; i < 12; i++) {
            double x;
            cin >> x;
            int x10 = static_cast<int>(x * 10 + 0.5); // 转为十分之一元,+0.5 防止截断误差
            if (x10 > 8000) {
                int excess = x10 - 8000;      // 超过 800 元的部分(单位:0.1 元)
                total_cents += excess * 2;    // 税额 = excess * 0.2 = excess * 2 / 10 → 单位:0.01 元
            }
        }
        // total_cents 是以「分」为单位的整数,直接除以 100.0 得元,保留两位小数
        cout << fixed << setprecision(2) << total_cents / 100.0 << endl;
    }
    

    优势
    零浮点误差:全程整数运算,结果绝对精确。
    符合信奥高可靠性要求:避免任何 double 累加不确定性。
    性能不变:仍是 O(1),且整数运算比浮点略快(但此处无感知)。

    2026-08-08 来自 新疆

    0
暂无数据

提交答案之后,这里将显示提交结果~

首页