#include #include #include using namespace std; stack < float > st; #define POP(f) if ( st.empty() ) cout << "Buffer underrun" << endl; else { f=st.top(); st.pop(); } int main() { while ( true ) { string s; char *tok; float f; getline( cin, s ); tok = strtok( (char*)s.c_str(), " " ); while ( NULL != tok ) { if ( sscanf( tok, "%f", &f )) st.push( f ); else { float f1, f2; POP(f2); POP(f1); switch( tok[0] ) { case '+': st.push( f1+f2 ); break; case '-': st.push( f1-f2 ); break; case '*': st.push( f1*f2 ); break; case '/': st.push( f1/f2 ); break; default: cout << "invalid operation" << endl; } } tok = strtok( NULL, " " ); } if ( st.size() == 1 ) { cout << st.top() << endl; st.pop(); } else return 1; } return 0; }