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())== '\n')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 =='\n')break;
			ch=getchar();
			getchar();
		}
		double num=0;
		while(!s.empty()){
			num+=s.top();s.pop();
		}
		printf("%0.2lf\n",num);
	}
	return 0;
}


posted @ 2017-02-09 15:58  朤尧  阅读(261)  评论(0编辑  收藏  举报