逆波兰表达式求值
class Solution {
public:
int evalRPN(vector<string>& tokens) {
int result = 0;
stack<int> st;
for(int i = 0; i < tokens.size(); i++){
if(tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/"){
int num1 = st.top(); st.pop();
int num2 = st.top(); st.pop();
int num3;
if(tokens[i] == "+"){
num3 = num1 + num2; st.push(num3);
}
else if(tokens[i] == "-"){
num3 = num2 - num1; st.push(num3);
}
else if(tokens[i] == "*"){
num3 = num2 * num1; st.push(num3);
}
else if(tokens[i] == "/"){
num3 = num2 / num1; st.push(num3);
}
cout << num1 << " " << num2 << " " << num3 << endl;
}else{
st.push(stoll(tokens[i]));
}
}
return st.top();
}
};