結果
問題 | No.708 (+ー)の式 |
ユーザー |
![]() |
提出日時 | 2018-07-03 14:30:39 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 955 bytes |
コンパイル時間 | 2,754 ms |
コンパイル使用メモリ | 164,572 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 12:33:32 |
合計ジャッジ時間 | 3,196 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h>using namespace std;int dfs(string str) {stack<int> s;stack<char> c;int score = 0;char nowc = '+';for (int i = 0; i < str.size(); i++) {if (str[i] == '(') {for (int j = i + 1; j < str.size(); j++) {if (str[j] == '(') {s.push(j);}if (str[j] == ')') {if (s.size()) {s.pop();continue;}switch (nowc) {case '+':score += dfs(str.substr(i + 1, j - i - 1));break;case '-':score -= dfs(str.substr(i + 1, j - i - 1));}i = j;}}}else if (str[i] == '+' || str[i] == '-') {nowc = str[i];}else {switch (nowc){case '+':score += str[i] - '0';break;case '-':score -= str[i] - '0';break;}}}return score;}void hawawa(){string str;cin >> str;cout << dfs(str) << "\n";}int main(){ios::sync_with_stdio(false);cin.tie(0);hawawa();return 0;}