#include <bits/stdc++.h>
using namespace std;
stack <int> a;
stack <char> b;
map <char, int> m;
void calc() {
int x = a.top(); a.pop();
int y = a.top(); a.pop();
char op = b.top(); b.pop();
if (op == '+') a.push((y + x) % 10000);
if (op == '*') a.push((y * x) % 10000);
}
int main() {
m['+'] = 1; m['*'] = 2;
string s;
cin >> s;
s += '+';
for (int i = 0; i < s.size(); i ++) {
char c = s[i];
if (isdigit(c)) {
int j = i, num = 0;
while (j < s.size() && isdigit(s[j])) {
num = num * 10 + s[j] - '0';
j ++;
}
a.push(num % 10000);
i = j - 1;
}
else {
while (b.size() && m[c] <= m[b.top()]) {
calc();
}
b.push(c);
}
}
cout << a.top();
return 0;
}
|