巧妙题啊!!!
看完代码,你就秒懂了
分成两拨 处理 ,不断 递归 即可
可以将 字符串 转化成 型
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
inline int wread(){
char c(getchar ());int wans (0),flag(1);
while (c<'0' ||c>'9'){if (c=='-') flag=-1; c=getchar ();}
while (c>='0' && c<='9'){wans=wans*10+c-'0';c=getchar ();}
return wans*=flag;
}
char s[100005];
double dfs (){
scanf ("%s",s);
if (s[0]=='*') return dfs()*dfs();
else if (s[0]=='-') return dfs()-dfs();
else if (s[0]=='/') return dfs()/dfs();
else if (s[0]=='+') return dfs()+dfs();
else return atof(s);
}
int main(){
printf("%f\n",dfs ());
return 0;
}