#include<iostream>#include<stack>#include<string>
using namespace std;
string s;
stack<double> num;//操作数
stack<char> op;//操作符intlevel(char c){if(c=='+'||c=='-')return1;elseif(c=='*'||c=='/')return2;elseif(c=='('||c==')')return3;elsereturn0;}
bool isSuper(char c1,char c2)//判断第二个操作优先级是否比第一个低{if(level(c2)<=level(c1))return true;elsereturn false;}doublecal(double left,double right,char op){if(op=='+')return left + right;if(op=='-')return left - right;if(op=='*')return left * right;if(op=='/')return left / right;}intmain(){
cin>>s;for(int i =0;i<s.length();i++){switch(s[i]){case'-':case'*':case'/':case'+':{if(op.size()==0) op.push(s[i]);//如果当前操作符为空,直接入栈else{//将该运算符之前优先级高的运算操作都计算完while(op.size()>0&&isSuper(op.top(),s[i])&&op.top()!='('){double right = num.top();num.pop();//弹出右操作数进行运算double left = num.top();num.pop();//弹出左操作数进行运算double res =cal(left,right,op.top());//计算完将答案压入栈中
op.pop();//弹出计算过的操作符
num.push(res);}
op.push(s[i]);//计算完前面优先级高的运算操作后将该运算符压入栈中}break;}case'(':op.push(s[i]);break;case')':{while(op.size()>0&&op.top()!='(')//将最近的一个左括号到这个右括号之间的操作全部进行运算{double right = num.top();num.pop();double left = num.top();num.pop();double res =cal(left,right,op.top());op.pop();
num.push(res);}
op.pop();//弹出左括号break;}default:num.push(double(s[i]-48));break;}}while(op.size()>0){double right = num.top();num.pop();double left = num.top();num.pop();double res =cal(left,right,op.top());op.pop();
cout<<"left\t"<<left<<" right\t"<<right<<" cal\t"<<cal<<endl;
num.push(res);}
cout<<num.top()<<endl;return0;}