結果
問題 |
No.708 (+ー)の式
|
ユーザー |
|
提出日時 | 2018-07-09 22:24:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 804 bytes |
コンパイル時間 | 592 ms |
コンパイル使用メモリ | 68,408 KB |
最終ジャッジ日時 | 2025-01-06 11:52:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <iostream> #include <string> using namespace std; int main() { string str; cin >> str; int r = 0; bool m = false; bool i = false; int ir = 0; bool im = false; for (auto c : str) { if (!i) { // インデントされていない if ('0' <= c && c <= '9') { int n = c - '0'; m ? r -= n : r += n; } else if (c == '+') m = false; else if (c == '-') m = true; else if (c == '(') { i = true; ir = 0; im = false; } } else { // インデントされている if ('0' <= c && c <= '9') { int n = c - '0'; im ? ir -= n : ir += n; } else if (c == '+') im = false; else if (c == '-') im = true; else if (c == ')') { i = false; m ? r -= ir : r += ir; } } } cout << r << endl; return 0; }