#include <bits/stdc++.h>

using namespace std;

int main(){
	string token;
	stack<int> operand;
	
	while(cin>>token){
		if(token=="+" || token=="-" || token=="*" || token=="/"){
			
			int first_operand = operand.top();	operand.pop();
			int second_operand = operand.top(); operand.pop(); 
			
			if(token=="+")	operand.push(first_operand+second_operand);
			if(token=="-")	operand.push(first_operand-second_operand);
			if(token=="*")	operand.push(first_operand*second_operand);
			if(token=="/")	operand.push(first_operand/second_operand);
		}else{
			operand.push(stoi(token));
		} 
		
	}
	cout<<operand.top()<<'\n';
    return 0;
} 

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: