dingxiangqian @ 2024-11-24 11:24:54
有输出每一步的代码,类型转换的数字很诡异而且运算不准,总是会多一个0.000009
#include<stack>
#include<iostream>
#include<string>
using namespace std;
double a,b;
string s;
stack <double>q;
int intn(string x)
{
int num;
for(int i=0;i<x.size();i++)
{
num=num*10+(x[i]-'0');
}
cout<<num<<endl;
return num;
}
int main(){
while(cin>>s)
{
if('0'<=s[0]&&s[0]<='9')q.push(intn(s));
if(s=="+")
{
a=q.top();q.pop();
b=q.top();q.pop();
q.push(a+b);
printf("%.6lf",q.top());
cout<<endl;
}
if(s=="+")
{
a=q.top();q.pop();
b=q.top();q.pop();
q.push(b-a);
printf("%.6lf",q.top());
cout<<endl;
}
if(s=="-")
{
a=q.top();q.pop();
b=q.top();q.pop();
q.push(b/a);
printf("%.6lf",q.top());
cout<<endl;
}
if(s=="*")
{
a=q.top();q.pop();
b=q.top();q.pop();
q.push(b*a);
printf("%.6lf",q.top());
cout<<endl;
}
}
printf("%.6lf",q.top());
return 0;
}