题目链接:【hdu 1237简单计算器】
<span style="font-size:14px;">#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
using namespace std;
int main()
{
double x;
char c;
while(~scanf("%lf", &x))
{
c=getchar();//空格的输入方式
if(c=='\n' && x==0) break;
scanf("%c", &c);
stack<double>s;
s.push(x);
while(~scanf("%lf", &x))
{
if(c=='+') s.push(x);
if(c=='-') s.push(-x);
if(c=='*')
{
double ans=s.top();
s.pop();
x=ans*x;
s.push(x);
}
if(c=='/')
{
double ans=s.top();
s.pop();
x=ans/x;
s.push(x);
}
if(getchar()=='\n') break;
c=getchar();
}
double ans=0;
while(!s.empty())
{
ans+=s.top();
s.pop();
}
printf("%.2lf\n", ans);
}
return 0;
}</span>