結果

問題 No.708 (+ー)の式
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-06-30 09:52:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,016 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 147,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 16:12:17
合計ジャッジ時間 1,827 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

struct Exe{
  string s;
  Exe(const string & S) : s(S){
    if(s[0] != '-') s = "+" + s;
  }

  int value(){
    int ans = 0;
    int cnt = 0;
    int si = 0;
    for(int i = 0;i < s.size();i++){
      char c = s[i];
      if(cnt == 0){
        if(c == '+') si = 1;
        else si = -1;
        cnt++;
      }
      else{
        if(c == '('){
          i++;
          int open = 1;
          string N = "";
          while(true){
            if(s[i] == ')'){
              open--;
              if(open == 0) break;
            }
            if(s[i] == '('){
              open++;
            }
            N += s[i];
            i++;
          }
          ans += si * (int)(Exe(N).value());
        }
        else{
          ans += si * (int)(c - '0');
        }
        cnt--;
      }
    }
    return ans;
  }
};

int main(){
  string s;
  cin >> s;
  cout << Exe(s).value() << endl;
}
0