#include <iostream> #include <unordered_map> #include <stack> #include <string> using namespace std; unordered_map<char,int> um={ {'#',0},{'$',1},{'+',2},{'-',2},{'*',3},{'/',3} }; double calculate(double,double,char ); int main() { ios::sync_with_stdio(false); // stack<char> ops; // stack<double> res; string todouble,todo; char c; while (getline(cin,todo)) { if(todo=="0") { break; } stack<char> ops; stack<double> res; todo=todo+" $"; ops.push('#'); todouble.clear(); for(int i=0;i<todo.size(); ) { c=todo[i]; if(c<='9'&&'0'<=c) { todouble.push_back(c);++i; } else if(c==' ') { if(todouble!="") { res.push(stod(todouble)); todouble.clear(); } ++i; } else { if(um[ops.top()]<um[c]) { ops.push(c);++i; } else { double a= res.top();res.pop(); double b= res.top();res.pop(); char cc=ops.top();ops.pop(); double ans=calculate(b,a,cc); res.push(ans); } } } printf("%.2f\n",res.top()); } } double calculate(double a,double b,char c) { switch (c) { case '+': return a+b; case '-': return a-b; case '*': return a*b; case '/': return a/b; } return 0; } // 64 位输出请用 printf("%lld")