#include #include using namespace std; int main() { string s; cin >> s; enum { STATE_SIGN1, STATE_DIGITS1, STATE_SIGN2, STATE_DIGITS2 } state = STATE_SIGN1; int sign1 = 1, sign2 = 1; int value1 = 0, value2 = 0; int op = 0; for (size_t i = 0; i < s.size(); ++i) { char ch = s[i]; switch (state) { case STATE_SIGN1: if (ch == '+') { } else if (ch == '-') { sign1 = -1; } else { value1 = (int)(ch - '0'); } state = STATE_DIGITS1; break; case STATE_DIGITS1: if (ch == '+') { op = -1; state = STATE_SIGN2; } else if (ch == '-') { op = 1; state = STATE_SIGN2; } else { value1 *= 10; value1 += (int)(ch - '0'); } break; case STATE_SIGN2: if (ch == '+') { } else if (ch == '-') { sign2 = -1; } else { value2 = (int)(ch - '0'); } state = STATE_DIGITS2; break; case STATE_DIGITS2: value2 *= 10; value2 += (int)(ch - '0'); break; } } int result = sign1 * value1 + sign2 * value2 * op; cout << result << endl; return 0; }