結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー MisterMister
提出日時 2020-04-22 10:09:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,093 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 81,248 KB
最終ジャッジ日時 2025-01-09 22:25:00
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 14
権限があれば一括ダウンロードができます

ソースコード

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;
    }

    std::cout << 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