結果

問題 No.708 (+ー)の式
ユーザー けーむけーむ
提出日時 2020-03-13 11:38:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,487 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 168,840 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 14:49:16
合計ジャッジ時間 2,412 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll f(string s) {
    ll tmp = 0, ans = 0;
    bool plus = false, minus = false;
    s += "=";
    rep(i, len(s)) {
        if ((s[i] >= '0') && (s[i] <= '9')) {
            tmp = tmp * 10 + (s[i] - '0');
            continue;
        }
        if ((!plus) && (!minus)) ans = tmp;
        else if (plus) ans += tmp;
        else ans -= tmp;
        plus = false; minus = false;
        if (s[i] == '+') plus = true;
        else if (s[i] == '-') minus = true;
        tmp = 0;
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    string ns = "", tmp = "";
    bool in = false;
    rep(i, len(s)) {
        if (s[i] == '(') {
            in = true;
            tmp = "";
        }
        else if (s[i] == ')') {
            ll v = f(tmp);
            ns += to_string(v);
            in = false;
        }
        else {
            if (in) tmp += s[i];
            else ns += s[i];
        }
    }
    cout << f(ns) << endl;
    return 0;
}
0