#include<bits/stdc++.h>
using namespace std;
char s[1005]; // 不能用string 否则atof会报错。 atof是c函数库,string是c++的
double bo(){
cin>>s;
// 可以用if ,else if ,else
switch(s[0]){
case '+':
return bo()+bo();
break;
case '-':
return bo()-bo();
break;
case '*':
return bo()*bo();
break;
case '/':
return bo()/bo();
break;
default:
return atof(s); //返回该字符的double类型, atoi 返回int
}
}
int main(){
freopen("cpp.in","r",stdin);
freopen("cpp.out","w",stdout);
printf("%.6f\n",bo());
return 0;
}
信息学奥赛一本通 1198:逆波兰表达式 (耙耙)
最新推荐文章于 2023-02-13 14:31:29 发布