# 题目链接

https://ac.nowcoder.com/acm/problem/16539

# 解题思路

（大佬思路及代码比较好理解）

debug了巨久，没想到自己能AC，栈这里我一直反应不过来

*还是大佬牛币！**

# 我的AC代码

```#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e4;
string str;
stack<ll> num;
stack<char> op;
int main(){
getline(cin,str);
ll n=str.length();
for(ll i=0;i<n;i++){
if(isdigit(str[i])) {
ll tmp=0;
while(isdigit(str[i])) tmp=str[i++]-'0'+tmp*10;
num.push(tmp%mod);
i--;
}
else {
while(!op.empty() && str[i]>=op.top()){//ASCII码的比较
ll num1=num.top();num.pop();
ll num2=num.top();num.pop();
if(op.top()=='+') num.push((num1+num2)%mod);
else num.push(num1*num2%mod);
op.pop();
}
op.push(str[i]);
}
}

while(!op.empty()){
ll num1=num.top();num.pop();
ll num2=num.top();num.pop();
if(op.top()=='+') num.push((num1+num2)%mod);
else num.push(num1*num2%mod);
op.pop();
}

cout<<num.top()%mod;
}
```

# 大佬AC代码

```#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e4;
stack<ll> num;
int main(){
ll t=0,tnum=0,ans=0;
char ch;
while(++t){
if(t&1LL) {
cin>>tnum;
num.push(tnum%mod);
}
else {
ch=getchar();
if(ch!='+' && ch!='*') break;
if(ch=='*') {
cin>>tnum;t++;
ll tmp=num.top();
num.pop();
num.push(tmp*tnum%mod);
}
}
}
while(!num.empty()){
ans=(ans+num.top())%mod;
num.pop();
}
cout<<ans<<endl;
}```