#include <bits/stdc++.h> #include <cctype> #include <stack> using namespace std; map<char, int> m; stack<double> shuzi; stack<char> op;//运算符 void cal(double a, double b, char opp) { if (opp == '+') shuzi.push(b + a); if (opp == '-') shuzi.push(b - a); if (opp == '*') shuzi.push(b * a); if (opp == '/') shuzi.push(b / a); } int main() { m.insert(make_pair('+', 1)); m.insert(make_pair('-', 1)); m.insert(make_pair('*', 2)); m.insert(make_pair('/', 2)); string s; while (cin >> s) { for (int i = 0; i < s.length();) { if (isdigit(s[i])) { string num = ""; while (i < s.length() && isdigit(s[i])) { num += s[i]; i++; } shuzi.push(stoi(num)); } else if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/') { if (op.empty() || m[op.top()] < m[s[i]]) { op.push(s[i]); } else { while (!op.empty() && m[op.top()] >= m[s[i]]) { char opp = op.top(); op.pop(); double a = shuzi.top(); shuzi.pop(); double b = shuzi.top(); shuzi.pop(); cal(a,b,opp); } op.push(s[i]); } i++; } } while (!op.empty()) { char opp = op.top(); op.pop(); double a = shuzi.top(); shuzi.pop(); double b = shuzi.top(); shuzi.pop(); cal(a,b,opp); } cout << shuzi.top(); } } // 64 位输出请用 printf("%lld")