結果
問題 |
No.708 (+ー)の式
|
ユーザー |
|
提出日時 | 2018-06-29 23:02:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 778 bytes |
コンパイル時間 | 1,570 ms |
コンパイル使用メモリ | 172,624 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-01 00:08:55 |
合計ジャッジ時間 | 2,393 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 RE * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; stack<int> op; bool braket = false; int ans = -1e5; int tmp = -1e5; for (int i = 0; i < (int) s.size(); i++) { if (s[i] == '+') op.push(1); else if (s[i] == '-') op.push(-1); else if (s[i] == '(') { braket = true; } else if (s[i] == ')') { braket = false; ans += op.top() * tmp; tmp = -1e5; op.pop(); } else { int n = s[i] - '0'; if (braket) { if (tmp == -1e5) tmp = n; else { tmp += op.top() * n; op.pop(); } } else { if (ans == -1e5) ans = n; else { ans += op.top() * n; op.pop(); } } } } cout << ans << endl; return 0; }