提交时间:2024-08-21 17:19:11
运行 ID: 180673
#include <bits/stdc++.h> using namespace std; const int mod=1e4; string s; stack<int>s1; stack<char>s2; int i; int pd(char c){ if(c=='+')return 1; else return 2; } void js(){ int a=s1.top();s1.pop(); int b=s1.top();s1.pop(); if(s2.top()=='+')s1.push((a+b)%mod); else s1.push((a*b)%mod); } int main(){ cin>>s; while(s[i]){ if(s[i]>='0'&&s[i]<='9'){ int v=0; while(s[i]>='0'&&s[i]<='9'){ v=v*10+s[i]-'0'; i++; }s1.push(v);i--; } else { while(!s2.empty()&&pd(s2.top())>pd(s[i])){ js();s2.pop(); }s2.push(s[i]); }i++; }while(!s2.empty()){ js();s2.pop(); } cout<<s1.top()%mod; return 0; }