题目
![](https://i-blog.csdnimg.cn/direct/7593dabf28e645c888f65ee656789e74.png)
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
stack<LL> num;
stack<char> op;
unordered_map<char, int> pr{{'+',1}, {'-',1}, {'*',2}, {'/',2}};
void cal()
{
LL b = num.top(); num.pop();
LL a = num.top(); num.pop();
char c = op.top(); op.pop();
LL res;
if(c == '+') res = a+b;
else if(c == '-') res = a-b;
else if(c == '*') res = a*b;
else if(c == '/') res = a/b;
num.push(res % 10000);
}
int main()
{
string s;
cin >> s;
for(int i = 0; i < s.size(); i++)
{
if(isdigit(s[i]))
{
int j = i;
stringstream ss;
while(j < s.size() && isdigit(s[j])) ss << s[j++];
i = j-1;
LL x;
ss >> x;
num.push(x);
}
else if(s[i] == '(') op.push(s[i]);
else if(s[i] == ')')
{
while(op.size() && op.top() != '(') cal();
op.pop();
}
else
{
while(op.size() && pr[s[i]] <= pr[op.top()]) cal();
op.push(s[i]);
}
}
while(op.size()) cal();
LL ans = num.top();
cout << ans % 10000;
return 0;
}