#include <iostream> #include <stack> using namespace std; int main() { string str; getline(cin, str); stack<int> sk1;//数字 stack<int> sk2;//运算符 sk2.push('('); str += ')'; bool flag = true; for (int i = 0; i < str.size(); ++i) { char c = str[i]; if (c == '(' || c == '[' || c == '{') { sk2.push('('); flag = false; continue; } else if (c == ')' || c == ']' || c == '}') { while (sk2.top() != '(') { int num1 = sk1.top(); sk1.pop(); int num2 = sk1.top(); sk1.pop(); char op = sk2.top(); sk2.pop(); if (op == '+') sk1.push(num1 + num2); else if (op == '-') sk1.push(num2 - num1); else if (op == '*') sk1.push(num1 * num2); else if (op == '/') sk1.push(num2 / num1); } sk2.pop(); } else if (isdigit(c)) { int pos = i; while (isdigit(str[i + 1])) ++i; string tmp = str.substr(pos, i - pos + 1); sk1.push(stoi(tmp)); flag = true; } else { if (!flag) { int pos = i; while (isdigit(str[i + 1])) ++i; string tmp = str.substr(pos, i - pos + 1); sk1.push(stoi(tmp)); flag = true; continue; } while (true) { char op_top = sk2.top(); if (op_top == '(' || (op_top == '+' || op_top == '-') && (c == '*' || c == '/')) { sk2.push(c); break; } else if (op_top == '+' && (c == '+' || c == '-') || op_top == '-' && (c == '+' || c == '-')) { sk2.pop(); int num1 = sk1.top(); sk1.pop(); int num2 = sk1.top(); sk1.pop(); if (op_top == '+') sk1.push(num1 + num2); else if (op_top == '-') sk1.push(num2 - num1); } else { sk2.pop(); int num1 = sk1.top(); sk1.pop(); int num2 = sk1.top(); sk1.pop(); if (op_top == '*') sk1.push(num1 * num2); else if (op_top == '/') sk1.push(num2 / num1); } } } } cout << sk1.top() << endl; return 0; } // 64 位输出请用 printf("%lld")