class Solution {
public:
int calPoints(vector<string>& ops) {
stack<int>stk;
for(auto str:ops)
{
if(str[0]>=48&&str[0]<=57||str[0]=='-')
{
stk.push(stoi(str));
}
else if(str=="+")
{
int temp=stk.top();
stk.pop();
int t2=stk.top();
stk.push(temp);
temp+=t2;
stk.push(temp);
}
else if(str=="D")
stk.push(stk.top()*2);
else if(str=="C")
stk.pop();
}
int res=0;
while(!stk.empty())
{
res+=stk.top();
stk.pop();
}
return res;
}
};