結果
| 問題 | No.708 (+ー)の式 | 
| コンテスト | |
| ユーザー |  risujiroh | 
| 提出日時 | 2018-11-05 02:18:47 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 987 bytes | 
| コンパイル時間 | 1,644 ms | 
| コンパイル使用メモリ | 165,784 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-20 20:09:38 | 
| 合計ジャッジ時間 | 2,296 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }
using Itr = string::const_iterator;
int expr(Itr& itr);
int term(Itr& itr);
int num(Itr& itr);
int expr(Itr& itr) {
  int res = term(itr);
  while (true) {
    if (*itr == '+') res += term(++itr);
    else if (*itr == '-') res -= term(++itr);
    else break;
  }
  return res;
}
int term(Itr& itr) {
  int res;
  if (*itr == '(') {
    res = expr(++itr);
    ++itr;
  } else res = num(itr);
  return res;
}
int num(Itr& itr) {
  return *itr++ - '0';
}
int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s; cin >> s;
  Itr itr = cbegin(s);
  cout << expr(itr) << '\n';
}
            
            
            
        