682. Baseball Game

时间:2023-03-09 16:12:34
682. Baseball Game
 static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
int calPoints(vector<string>& ops)
{
int lastvalid=;
int sz=ops.size();
vector<int> sore(sz+,INT_MIN);
for(string &s:ops)
{
if(s[]=='+')
{
sore[lastvalid]=sore[lastvalid-]+sore[lastvalid-];
lastvalid++;
}
else if(s[]=='D')
{
sore[lastvalid]=sore[lastvalid-]*;
lastvalid++;
}
else if(s[]=='C')
lastvalid--;
else
sore[lastvalid++]=stoi(s);
}
return accumulate(sore.begin(),sore.begin()+lastvalid,);
}
};

用栈或者vector都行,string转int可以直接stoi,学到了,妈个腿