結果

問題 No.708 (+ー)の式
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-02-24 02:26:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 945 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 146,096 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 06:49:29
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int cal(string s) {
    int a;
    if (s[0]!='(') {
        a=(int)s[0]-'0';
        if (s.length()>1) {
            switch(s[1]) {
                case '+':
                    a+=cal(s.substr(2));
                    break;
                case '-':
                    a-=cal(s.substr(2));
                    break;
            }
        }
    }
    else {
        size_t i=0;
        while(s[i]!=')') {
            i++;
        }
        a=cal(s.substr(1,i-1));
        if (s.length()>i+1) {
            switch(s[i+1]) {
                case '+':
                    a+=cal(s.substr(i+2));
                    break;
                case '-':
                    a-=cal(s.substr(i+2));
                    break;
            }
        }
    }
    return a;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << cal(s) << endl;
    return 0;
}
0