kedaOJ#P0401. 逆波兰表达式
题目 #P0401. 逆波兰表达式
思路
都写着递归了,还算简单
代码
#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);
break;
}
}
int main() {
printf("%lf\n", exp());
return 0;
}
这是mcr130102的博客,转载请注明出处