#include #include using namespace std; int main() { const char p = '+'; const char m = '-'; const char bl = '('; const char br = ')'; bool pos = true; bool bracket = false; bool tmp_pos = true; string s; cin >> s; long res = 0; for (int i = 0; i < s.size(); i++){ if (s[i] == p){ pos = true; continue; } if (s[i] == m){ pos = false; continue; } if (s[i] == bl){ tmp_pos = pos; i++; while (s[i] != br){ if (s[i] == p) tmp_pos = pos; else if (s[i] == m) tmp_pos = !pos; else { if (tmp_pos == true) res += static_cast(s[i] - '0'); else res -= static_cast(s[i] - '0'); } i++; } } if (s[i] == br){ bracket = false; continue; } if (pos == true) res += static_cast(s[i] - '0'); else res -= static_cast(s[i] - '0'); } cout << res << "\n"; }