http://acm.hdu.edu.cn/showproblem.php?pid=1237
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<stack> #include<algorithm> using namespace std; int main() { double n, m; char c; while(~scanf("%lf", &n)) { c=getchar(); if(c==' ' && n==0) break; stack<double> Stack; Stack.push(n); c=getchar(); while(~scanf("%lf", &m)) { if(c=='+') Stack.push(m); else if(c=='-') Stack.push(0-m); else if(c=='*') { n=Stack.top(); Stack.pop(); Stack.push(n*m); } else if(c=='/') { n=Stack.top(); Stack.pop(); Stack.push(n/m); } if(getchar()==' ') break; c=getchar(); } double sum=0; while(!Stack.empty()) { sum+=Stack.top(); Stack.pop(); } printf("%.2f ", sum); } return 0; }