#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int func(string s) { int num = 0; string fugo = "+"; for (int i = 0; i < s.length(); i++) { if (s[i] == '+' || s[i] == '-') { fugo = s[i]; } else { if (fugo == "+") { if (s[i + 1] != '+' && s[i + 1] != '-' && (int)s[i + 1] - 48 >= 0 && (int)s[i + 1] - 48 <= 9) { num += stoi(s.substr(i, 2)); i++; } else { num += (int)s[i] - 48; } } else { if (s[i + 1] != '+' && s[i + 1] != '-' && (int)s[i + 1] -48 >= 0 && (int)s[i + 1] - 48 <= 9) { num -= stoi(s.substr(i, 2)); i++; } else { num -= (int)s[i] - 48; } } } } return num; } int main() { int i, j, k; string s; string kako[100]; int cnt = 0; cin >> s; for (i = 0; i < s.length(); i++) { if (s[i] == '(') { for (j = i + 1; j < s.length(); j++) { if (s[j] == ')') { kako[cnt] = s.substr(i + 1, j - (i + 1)); int num = func(kako[cnt]); cnt++; if (num < 0) { if (s[i - 1] == '+') { s.replace(i-1, j - i + 2, to_string(num)); } else if ( s[i - 1] == '-') { num = abs(num); s[i - 1] = '+'; s.replace(i, j - i + 1, to_string(num)); } else { s.replace(i, j - i + 1, to_string(num)); } } else { s.replace(i, j - i + 1, to_string(num)); } i = -1; break; } } } } int sum = func(s); cout << sum << endl; getchar(); getchar(); return 0; }