实现代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
stack<int>s;
stack<char>t;
int n,m,z,p1,p2,q; char c;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>m;
s.push(m);
}
for(int i=1;i<n;i++)
{
cin>>c;
t.push(c);
}
while(!t.empty())
{
p1=s.top();
s.pop();
p2=s.top();
s.pop();
q=t.top();
t.pop();
if(q=='+')
z=p1+p2;
else if(q=='-')
z=p2-p1;
else if(q=='*')
z=p1*p2;
else
{
if(p1==0)
{
printf("ERROR: %d/0",p2);
return 0;
}
else
z=p2/p1;
}
s.push(z);
}
cout<<s.top();
return 0;
}