#include <cctype> #include <iostream> #include <unordered_map> #include <stack> #include <algorithm> using namespace std; stack<char> op; stack<float> num; unordered_map<char, int> prime{{'+', 1}, {'-', 1}, {'*', 2},{'/', 2}}; void eval(){ float b = num.top(); num.pop();//第2个操作数 float a = num.top(); num.pop();//第1个操作数 char c = op.top(); op.pop(); float 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; while(getline(cin, str) && str != "0"){ for(int i = 0; i < str.size(); i ++){ if(str[i] == ' ') continue; else if (isdigit(str[i])){//数字处理 float x = 0; for(; i < str.size() && isdigit(str[i]); i ++) x = x * 10 + str[i] - '0'; num.push(x); i --; } else { while (!op.empty() && prime[op.top()] >= prime[str[i]]) eval(); op.push(str[i]); } } //处理栈中剩余的运算符 while(!op.empty()) eval(); printf("%.2f\n", num.top()); num.pop();//清空 } return 0; }