#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 == "+") { num += (int)s[i] - 48; } 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++; s.replace(i, j - i+1, to_string(num)); i = -1; break; } } } } int sum = func(s); cout << sum << endl; getchar(); getchar(); return 0; }