結果
| 問題 | No.708 (+ー)の式 | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2018-06-29 22:43:24 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 750 bytes | 
| コンパイル時間 | 651 ms | 
| コンパイル使用メモリ | 74,764 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-01 00:03:56 | 
| 合計ジャッジ時間 | 1,197 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
int f(string& s) {
    int n = s.size();
    int sgn = 1;
    int r = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '(') {
            int j = i;
            while (s[j] != ')') j++;
            string t = s.substr(i + 1, j - i - 1);
            r += f(t) * sgn;
            i = j;
        } else if (s[i] == '+') {
            sgn = 1;
        } else if (s[i] == '-') {
            sgn = -1;
        } else {
            r += (s[i] - '0') * sgn;
        }
    }
    return r;
}
int main() {
    string s;
    cin >> s;
    cout << f(s) << endl;
    return 0;
}
            
            
            
        