原题链接:682. 棒球比赛
solution:
class Solution {
public:
int calPoints(vector<string>& ops) {
vector<int> st;
int i=0;
for(auto& it : ops){
if(it == "+"){
st.push_back(st[i-2] + st[i-1]);
i++;
}
else if(it == "D"){
st.push_back(2 * st[i-1]);
i++;
}
else if(it == "C"){
i--;
st.pop_back();
}
else{
st.push_back(stoi(it));
i++;
}
}
int res=0;
for(int i=0;i<st.size();i++){
res+=st[i];
}
return res;
}
};