逆波兰表达式

xiaoxiao2021-02-27  223

//逆波兰表达式递归求解 #include<bits/stdc++.h> using namespace std; #include<cstdlib>// atof函数:将字符串类型的浮点数转化为double 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",exp()); return 0; }
转载请注明原文地址: https://www.6miu.com/read-11102.html

最新回复(0)