这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。
//ID:百练oj2694 逆波兰表达式 //网站:C++奋斗乐园|C++论坛|算法论坛|ACM/ICPC论坛 //地址:http://www.cppleyuan.com/ //个人主页:www.wutianqi.com
/*个人感觉这个递归很经典,大家可以多学习一下*/
/*注意对atof()函数的使用*/
#include
#include
#include
#include
#include
#include
using namespace std;
double exp()
{
char a[10];
scanf("%s", a);
switch(a[0])
{
case '+':
return exp() + exp();
case '-':
return exp() - exp();
case '*':
return exp() * exp();
case '/':
return exp() / exp();
default:
return atof(a);
}
}
int main()
{
double ans;
ans = exp();
printf("%f\n", ans);
return 0;
}