結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー MisterMister
提出日時 2020-04-22 10:15:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,210 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 82,060 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 22:52:04
合計ジャッジ時間 2,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>

using lint = long long;

constexpr lint D = 10000000000;

void solve() {
    int n;
    std::cin >> n;

    lint x = 0, f = 0;
    while (n--) {
        std::string s;
        std::cin >> s;
        if (!std::count(s.begin(), s.end(), '.')) s += ".0";

        bool neg = (s.front() == '-');
        if (neg) s.erase(s.begin());

        lint nx = 0;
        while (s.front() != '.') {
            nx = nx * 10 + s.front() - '0';
            s.erase(s.begin());
        }

        s.erase(s.begin());

        while (s.length() < 10) s.push_back('0');
        lint nf = std::stoll(s);

        x += nx * (neg ? -1 : 1);
        f += nf * (neg ? -1 : 1);
    }

    while (f < 0) {
        f += D;
        --x;
    }
    while (f >= D) {
        f -= D;
        ++x;
    }

    bool neg = (x < 0);
    if (neg && f > 0) {
        ++x;
        f = D - f;
    }

    std::cout << (x == 0 && neg ? "-" : "") << x << "."
              << std::setw(10) << std::setfill('0') << f
              << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0