class Solution {
public:
int calculate(string s) {
stack<int> bolan;
char sign = '+';
long num = 0;
int len = s.size();
for (int i = 0; i<len; ++i)
{
char c = s[i];
if (isdigit(c))
{
num = num * 10 + c - '0';
}
if ((!isdigit(c)&&c!=' ') || i == len - 1)
{
//bolan.push(num);
if (sign == '+')
bolan.push(num);
else if (sign == '-')
bolan.push(-1 * num);
else if (sign == '*')
{
long temp = bolan.top();
bolan.pop();
bolan.push(temp*num);
}
else if (sign == '/')
{
long temp = bolan.top();
bolan.pop();
bolan.push(temp/num);
}
sign = c;
num = 0;
}
}
long result = 0;
while (!bolan.empty())
{
result = result + bolan.top();
bolan.pop();
}
return result;
}
};