Calculate the value using stacks.
class Solution {
public:
int evalRPN(vector<string> &tokens) {
stack<int> integers;
stack<string> symbols;
for(vector<string>::iterator i=tokens.begin();i!=tokens.end();i++)
{
const char *tmp = (*i).c_str();
if(strcmp(tmp,"+")==0 || strcmp(tmp,"-")==0 || strcmp(tmp,"*")==0 || strcmp(tmp,"/")==0)
{
int b = integers.top(); integers.pop();
int a = integers.top(); integers.pop();
int result;
if (strcmp(tmp,"+")==0)
result = a+b;
else if (strcmp(tmp,"-")==0)
result = a-b;
else if (strcmp(tmp,"*")==0)
result = a*b;
else if (strcmp(tmp,"/")==0)
result = a/b;
else result = 0;
integers.push(result);
}
else
{
int x= atoi(tmp);
integers.push(x);
}
}
return integers.top();
}
};