結果

問題 No.3062 A + B
ユーザー mencottonmencotton
提出日時 2020-04-01 22:41:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 9,979 ms
コンパイル使用メモリ 330,808 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 19:24:06
合計ジャッジ時間 8,793 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,360 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,356 KB
testcase_10 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using Bint = boost::multiprecision::cpp_int;

string s;

Bint num(int &index) {
    Bint ret = 0;
    while (index < s.size() && isdigit(s[index])) {
        ret *= 10;
        ret += s[index] - '0';
        index++;
    }
    return ret;
}

Bint calc(int &index) {
    Bint ret = num(index);
    while (index < s.size()) {
        if (s[index] == '+') {
            index++;
            ret += num(index);
        } else if (s[index] == '-') {
            index++;
            ret -= num(index);
        }
    }
    return ret;
}

int main() {
    string a, b;
    cin >> a >> b;
    s = "0" + a + b;
    int usi = 0;
    cout << calc(usi) << endl;
    return 0;
}
0