結果

問題 No.8062 A + B
ユーザー trineutron
提出日時 2020-04-01 22:21:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 196,236 KB
最終ジャッジ日時 2025-01-09 12:11:34
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    string a, b, formula;
    cin >> a >> b;
    formula = a + b + '+';
    __int128_t ans = 0, cache = 0, sign = 1;
    for (char c : formula) {
        if (c == '+') {
            ans += sign * cache;
            cache = 0;
            sign = 1;
        } else if (c == '-') {
            ans += sign * cache;
            cache = 0;
            sign = -1;
        } else {
            cache = 10 * cache + c - '0';
        }
    }
    if (ans < 0) {
        cout << '-';
        ans = -ans;
    }
    string output;
    __int128_t ans_copy = ans;
    while (ans_copy) {
        output.push_back(ans_copy % 10 + '0');
        ans_copy /= 10;
    }
    reverse(output.begin(), output.end());
    cout << output << endl;
}
0