使用STL的stack容易实现。
한국어< 中文 فارسی English ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM GPL2.0 2003-2011 HUSTOJ Project TEAM Anything about the Problems, Please Contact Admin:admin
#include<iostream> #include<stack> #include<iomanip> using namespace std; int main() { stack<double>a; int n; while(cin>>n) { double temp, sum; sum = 0; char c; cin >> temp; a.push(temp); for(int i = 1; i < n; i++) { cin >> c >> temp; if( c == '+' ) a.push(temp); else if( c == '-' ) a.push(-temp); else if(c == '*') { temp *= a.top(); a.pop(); a.push(temp); } } cin >> c; while(!a.empty()) { sum += a.top(); a.pop(); } cout << fixed << setprecision(2) << sum << endl; } }