P1449 后缀表达式【洛谷】

在这里插入图片描述

#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();
}
		
发布了180 篇原创文章 · 获赞 22 · 访问量 9007

猜你喜欢

转载自blog.csdn.net/qq_44622401/article/details/104315102