#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include <algorithm>
using namespace std;
int main()
{
double n,m;
char c;
while(scanf("%lf",&n))
{
c=getchar();
if(c=='\n'||n==0)
break;
stack<double> s;
s.push(n);
scanf("%c",&c);
while(scanf("%lf",&n))
{
if(c=='*')
{
m=s.top();
m*=n;
s.pop();
s.push(m);
}
if(c=='/')
{
m=s.top();
m/=n;
s.pop();
s.push(m);
}
if(c=='+')
s.push(n);
if(c=='-')
s.push(0-n);
if(getchar()=='\n')
break;
c=getchar();
}
double sum=0;
while(!s.empty())
{
sum+=s.top();
s.pop();
}
printf("%0.2lf\n",sum);
}
return 0;
}
1237 简单计算器
最新推荐文章于 2020-06-27 09:55:08 发布