/* g++ -std=c++11 -Wall -O2 -o main.exe main.cpp ./main.exe */ #include #include #include #include //intの最大値: INT_MAX //longの最大値: LONG_MAX //long longの最大値: LLONG_MAX #include #include #include #include #include #include #include #include #include #include #include //最大公約数: gcd() //最小公倍数: lcm() #define ll long long int using namespace std; template void sortasc(vector &v){ //vectorを昇順にソート sort(v.begin(), v.end(), std::less()); return; } template void sortdesc(vector &v){ //vectorを降順にソート sort(v.begin(), v.end(), std::greater()); return; } //------------------------------------------------------------------------------ string S; int index; int k(){ int val = 0; char t; while(1){ t = S[index++]; if(t == ')'){ return val; } else if(t == '+'){ val += (int)(S[index++] - '0'); } else if(t == '-'){ val -= (int)(S[index++] - '0'); } else{ val += (int)(t - '0'); } } } int main(){ cin >> S; int val = 0; char t; index = 0; while(index < (int)(S.size())){ t = S[index++]; if(t == '+'){ if(S[index] == '('){ index++; val += k(); } else val += (int)(S[index++] - '0'); } else if(t == '-'){ if(S[index] == '('){ index++; val -= k(); } else val -= (int)(S[index++] - '0'); } else if(t == '('){ val += k(); } else{ val += (int)(t - '0'); } cout << val << endl; } cout << val << endl; return 0; }