#include using namespace std; bool isOp(string c){ return c == "+" || c == "-" || c == "*" || c == "/"; } int eval(string s){ stack stk; stringstream s1(s); string c; while (s1>>c){ if(isOp(c)){ int a = stk.top(); stk.pop(); int b = stk.top(); stk.pop(); if (c == "+") stk.push(b + a); if (c == "-") stk.push(b - a); if (c == "*") stk.push(b * a); if (c == "/") stk.push(b / a); }else stk.push(stoi(c)); } return stk.top(); } int main() { string s = "24 9 6 3 / + 5 - * 4 +"; cout << "answer:" << eval(s) << endl; return 0; }