后缀表达式 洛谷

题目https://www.luogu.org/problemnew/show/P1449

#include<cstdio>
#include<iostream>
#include<string.h>
#include<stack>
using namespace std;
char a[10000];
int main()
{
	int i=0;
	stack<double>a;
	char ctf;int sum=0;
	while(1)
	{
		int c;int f;
		ctf = getchar();
		switch(ctf)
		{
			case '+':c = a.top();a.pop();f=( (a.top())+c );a.pop();a.push(f) ;break;
			case '/':c = a.top();a.pop();f=((a.top())/c);a.pop();a.push(f) ;break;
			case '*':c = a.top();a.pop();f=( (a.top())* c);a.pop();a.push(f) ;break;
			case '@':printf("%.lf\n",a.top());return 0;;
			case '-':c = a.top();a.pop();f=((a.top()) - c);a.pop();a.push(f) ;break;
			case '.':a.push(sum);sum=0;break;
			default:sum = sum * 10 + ctf-'0';break;
		}
	}
	return 0;
 } 

猜你喜欢

转载自blog.csdn.net/qq_43568078/article/details/84996875