C 库函数 double atof(const char *str) 把参数 str 所指向的字符串转换为一个浮点数(类型为 double 型)。
声明
下面是 atof() 函数的声明。
double atof(const char *str)
参数
- str -- 要转换为浮点数的字符串。
返回值
函数返回转换后的双精度浮点数,如果没有执行有效的转换,则返回零(0.0)。
本题中“逆波兰表达式”的定义:
1)
一个数是一个逆波兰表达式,值为该数
2)
运算符 逆波兰表达式 逆波兰表达式 是逆波兰表达
式 值为两个逆波兰表达式的值运算的结果
样例输入
* + 11.0 12.0 + 24.0 35.0
样例输出
1357.000000
提示:
:(11.0+12.0)*(24.0+35.0)
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
double exp()
{
char s[20];
cin >> s; // 流操作符,读完地址偏移
switch (s[0])
{
case '+':
return exp() + exp();
case '-':
return exp() - exp();
case '*':
return exp() * exp();
case '/':
return exp() / exp();
default:
//return atof(s[0]);
return atof(s);
break;
}
}
int main()
{
printf("%lf", exp());
}