【模板题】1696:逆波兰表达式——递归

1696:逆波兰表达式

样例输入
* + 11.0 12.0 + 24.0 35.0
样例输出
1357.000000
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
double fun()
{
	char s[100];
	cin>>s;
	if (isdigit(s[0]))
		return atof(s);
	if (s[0]=='+')
		return (fun()+fun());
	else if (s[0]=='-')
		return (fun()-fun());
	else if (s[0]=='*')
		return (fun()*fun());
	else if (s[0]=='/')
		return (fun()/fun());
}
int main()
{
	printf("%f\n", fun());
	return 0;
}
ps:天啊我是太久没写递归了嘛T T

猜你喜欢

转载自blog.csdn.net/always_ease/article/details/80698407
今日推荐