题目:P1449 后缀表达式 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
char c;
int now=0;
stack<int>s;
int x1=0,x2=0;
while((c=getchar())!='@')
{
if(c>='0'&&c<='9')
{
now*=10;now+=c-'0';
}
else if(c=='.')
{
s.push(now);
now=0;
}
else
{
x1=s.top();
s.pop();
x2=s.top();
s.pop();
if(c=='+')
s.push(x1+x2);
if(c=='-')
s.push(x2-x1);
if(c=='*')
s.push(x2*x1);
if(c=='/')
s.push(x2/x1);
}
}
cout<<s.top();
return 0;
}