int evalRPN(vector<string>& tokens) {
int n=tokens.size();
stack<int> s1;
for(int i=0;i<n;i++){
if(tokens[i]=="+"||tokens[i]=="-"||tokens[i]=="*"||tokens[i]=="/"){
unsigned int t1=s1.top();
s1.pop();
unsigned int t2=s1.top();
s1.pop();
unsigned int t3=0;
if(tokens[i]=="+")
t3=t1+t2;
else if(tokens[i]=="-")
t3=t2-t1;
else if(tokens[i]=="*")
t3=t1*t2;
else t3=t2/t1;
s1.push(t3);
}
else{
int temp=stoi(tokens[i]);
s1.push(temp);
}
}
int ans=s1.top();
return ans;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: