/*
运算表达式主要在设计优先级上
无括号的情况下设置四个优先级(从高到低为):(* /)、(+ -)、($)、(#)
其中#放栈底,$放字符串结尾
遇到数字压入数字栈,遇到符号,如果优先级>栈顶优先级则压入,如果优先级<栈顶优先级则弹出栈顶和两个运算符进行运算,结果压入数字栈
注意:当运算符栈中只有#和$的时候,数组栈中只剩一个数字,那就是结果
*/
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int getleval(char op){
if(op=='*'||op=='/'){
return 2;
}else if(op=='+'||op=='-'){
return 1;
}else if(op=='$'){
return 0;
}else return -1;
}
float compute(float x,float y,char op){
if(op=='+'){
return x+y;
}else if(op=='-'){
return x-y;
}else if(op=='*'){
return x*y;
}else return x/y;
}
int main(){
string s;
stack<char> op;
stack<float> num;
op.push('#');
while(getline(cin,s)){
if(s=="0")break;
s+="$";
float res=0;int i=0;
while(i<s.size()){
if(s[i]>='0'&&s[i]<='9'){
res=0;
while(s[i]>='0'&&s[i]<='9'){
res=res*10+s[i]-'0';
i++;
}num.push(res);
}else if(s[i]==' '){
i++;
}else{
if(getleval(s[i])>getleval(op.top())){
op.push(s[i]);
i++;
}else{
char o=op.top();
op.pop();
float num2=num.top();
num.pop();
float num1=num.top();
num.pop();
num1=compute(num1,num2,o);
num.push(num1);
}
}
}printf("%.2f\n",num.top());
num.pop();
op.pop();
}
return 0;
}