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;
}
posted @ 2024-06-26 23:08  mcr130102  阅读(6)  评论(0编辑  收藏  举报
请不要抄袭任何人的博客,这是对一名开发者最基本的尊重。