https://leetcode-cn.com/problems/baseball-game/
思路:用栈模拟即可。
class Solution {
public:
int calPoints(vector<string>& ops) {
vector<int> vec;
int siz=ops.size();
int ans=0;
for(int i=0;i<siz;i++){
int n=vec.size();
if(ops[i][0]=='+'){
vec.push_back(vec[n-1]+vec[n-2]);
ans+=vec[n];
}
else if(ops[i][0]=='D'){
vec.push_back(vec[n-1]*2);
ans+=vec[n];
}
else if(ops[i][0]=='C'){
ans-=vec[n-1];
vec.pop_back();
}
else{
vec.push_back(stoi(ops[i]));
ans+=vec[n];
}
}
return ans;
}
};