class Solution {
public:
int calPoints(vector<string>& ops)
{
stack<int> num;
int res = 0;
for(int i = 0;i < ops.size();i++)
{
if(ops[i] == "C")
{
num.pop();
}
else if(ops[i] == "D")
{
int m = num.top();
m = m * 2;
num.push(m);
}
else if(ops[i] == "+")
{
int n = num.top();
num.pop();
int a = num.top();
int c = a + n;
num.push(n);
num.push(c);
}
else
{
int b = stoi(ops[i]);
num.push(b);
}
}
while(!num.empty())
{
res += num.top();
num.pop();
}
return res;
}
};