#include<bits/stdc++.h>
using namespace std;
stack<int>s;
int t,x,y;
char ch;
int main()
{
while(ch!='@')
{
ch=getchar();
switch(ch)
{
case '+':x=s.top();s.pop();y=s.top();s.pop();s.push(x+y);break;
case '-':x=s.top();s.pop();y=s.top();s.pop();s.push(y-x);break;
case '*':x=s.top();s.pop();y=s.top();s.pop();s.push(x*y);break;
case '/':x=s.top();s.pop();y=s.top();s.pop();s.push(y/x);break;
case '.':s.push(t);t=0;break;
default :t=t*10+ch-'0';break;
}
}
cout<<s.top();
}
P1449 后缀表达式【洛谷】
猜你喜欢
转载自blog.csdn.net/qq_44622401/article/details/104315102
今日推荐
周排行