#define _CRT_SECURE_NO_WARNINGS 1 #include <bits/stdc++.h> using namespace std; int youxianji(char c) {//优先级 if (c == '#')return 0; else if (c == '$')return 1; else if (c == '+' || c == '-')return 2; else if (c == '*' || c == '/')return 3; return 0;//必须返回一个默认,否则oj会报错 } double getNumber(string str, int& index) {//获取数字 double number = 0; while (isdigit(str[index])) { number = number * 10 + str[index] - '0'; index++; } return number; } double cauculate(double x, double y, char op) {//计算 double result = 0; if (op == '+')result = x + y; else if (op == '-')result = x - y; else if (op == '*')result = x * y; else if (op == '/')result = x / y; return result; } int main() { string str; while (cin >> str) { int index = 0; stack<char>oper; stack<double>data; str = str + '$'; oper.push('#'); while (index < str.size()) { if (isdigit(str[index])) { data.push(getNumber(str, index)); } else if (youxianji(oper.top()) < youxianji(str[index])) { oper.push(str[index]); index++; } else { double y = data.top(); data.pop(); double x = data.top(); data.pop(); char op = oper.top(); oper.pop(); double result = cauculate(x, y, op); data.push(result); } } int B=data.top();//强制类型转换 printf("%d\n", B); } return 0; }