/**************************************************************** 
 * Description: 输出算术式结果 例如：(12+2)/(13-2*3)
 * Author: Alex Li
 * Date: 2023-09-30 16:06:10
 * LastEditTime: 2024-01-28 20:08:31
****************************************************************/
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
using namespace std;
stack <int> num;
stack <char>  op;

//计算
void eval(){
    //在数字栈中取两数，在操作符栈中取一个符号
    int b=num.top();num.pop();//取数，出栈
    int a=num.top();num.pop();//取数，出栈
    char c=op.top();op.pop();//取操作符，出栈
    int x;
    if(c=='+')x=a+b;
    else if(c=='-')x=a-b;
    else if(c=='*')x=a*b;
    else if(c=='/')x=a/b;
    num.push(x);//把式子计算好，重新放回去 
}
int main(){
    string str;
    cin>>str;
    //设定符号优先级，采用map数据结构，也可以采用结构体或数组。
    map<char, int> pr;
    pr.insert(pair<char, int>('+',1));
    pr.insert(pair<char, int>('-',1));
    pr.insert(pair<char, int>('*',2));
    pr.insert(pair<char, int>('/',2));
   
    for (int i = 0; i <str.size(); i++){
        char c=str[i];
        if(isdigit(c)){//isdigit函数主要用于检查其参数是否为十进制数字字符。
            int x=0,j=i;
            while(j<str.size()&&isdigit(str[j])){
                x=x*10+str[j++]-'0';
            }
            i=j-1;
            num.push(x);
        }
        else if(c=='(')op.push(c);
        else if(c==')'){ 
            while(op.top()!='(')eval();
            op.pop();
        }
        else{
            while(op.size()&&op.top()!='('&&pr[op.top()]>=pr[c])eval();
//判断，如果符号栈里有符号，并且不是'('，而且新读的操作符优先级小于等于符号栈顶符号的有级，则计算。
            op.push(c); //把新读到的符号压倒栈里。
        }
     
    }
      while(op.size())eval();
      cout<<num.top()<<endl;
      return 0;

}
