hdu--1237--简单计算器

#include<iostream>
#include<stack>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
	double a;
	while(cin>>a)
	{
		char ch;
		if(a == 0){
			if((ch=getchar())== '
')break;
		}else getchar();
		stack<double> s;
		while(!s.empty())s.pop();
		s.push(a);
		ch=getchar();getchar();
		while(cin>>a){
			if(ch == '*'){
				a=s.top()*a;
				s.pop();
				s.push(a);
			}else if(ch == '/'){
				a=s.top()/a;
				s.pop();
				s.push(a);
			}else if(ch =='-'){
				s.push(-a);
			}else if(ch == '+'){
				s.push(a);
			}
			ch=getchar();
			if(ch =='
')break;
			ch=getchar();
			getchar();
		}
		double num=0;
		while(!s.empty()){
			num+=s.top();s.pop();
		}
		printf("%0.2lf
",num);
	}
	return 0;
}


原文地址:https://www.cnblogs.com/langyao/p/7251928.html