#include<algorithm>
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<climits>
#define eps 1e-9
#define ll long long
using namespace std;
int op[300];
int main()
{
double x,y;
stack<double>numb;
stack<char>exp;
op['-'] = op['+'] = 2;
op['*'] = op['/'] = 1;
while(cin>>x)
{
while(!numb.empty())numb.pop();
while(!exp.empty())exp.pop();
numb.push(x);
char c = getchar();
if(c == '\n')break;
c = getchar();
exp.push(c);
getchar();
while(cin>>x)
{
numb.push(x);
c = getchar();
if(c == '\n')break;
c = getchar();
while(!exp.empty()&&op[c]>=op[exp.top()])
{
char cc = exp.top();
x = numb.top();
numb.pop();
y = numb.top();
numb.pop();
if(cc == '+')numb.push(y+x);
if(cc == '-')numb.push(y-x);
if(cc == '*')numb.push(y*x);
if(cc == '/')numb.push(y/x);
exp.pop();
}
exp.push(c);
getchar();
}
while(!exp.empty())
{
char cc = exp.top();
x = numb.top();
numb.pop();
y = numb.top();
numb.pop();
if(cc == '+')numb.push(y+x);
if(cc == '-')numb.push(y-x);
if(cc == '*')numb.push(y*x);
if(cc == '/')numb.push(y/x);
exp.pop();
}
if(numb.size()!=1)while(1);
printf("%.2lf\n",numb.top());
}
return 0;
}
九度1019 简单计算器
最新推荐文章于 2020-02-25 20:45:08 发布