陈柏诚 • 2年前
using namespace std;
stack n; int main() { //freopen("enpr.in","r",stdin); //freopen("enpr.out","w",stdout); int a,b; char c; cin>>a; a=a%Mod; n.push(a); while(cin>>c>>b) {
if(c=='*')//乘号的话就把之前的栈顶*b给存进去
{
a=n.top();
n.pop();
n.push(a*b%Mod);//%Mod防止爆掉
}
else
n.push(b);
} short ans=0;//四位数用short就可以 while(!n.empty()) {
a=(a+n.top())%Mod;
n.pop();
} cout<<a<<endl; return 0; }
评论: