解法:
#include<iostream>
#include<stack>
using namespace std;
int main() {
char a;
stack<int> sk;
while (cin >> a && a != '#') {
if (a >= '0' && a <= '9') {
sk.push(a - '0');
}
else {
int num2 = sk.top();
sk.pop();
int num1 = sk.top();
sk.pop();
if (a == '*') sk.push(num1 * num2);
if (a == '/') sk.push(num1 / num2);
if (a == '+') sk.push(num1 + num2);
if (a == '-') sk.push(num1 - num2);
}
}
cout << sk.top();
return 0;
}