标签:class ase AC pre tor win solution wing ali
1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 int calPoints(vector<string>& ops) 12 { 13 int lastvalid=0; 14 int sz=ops.size(); 15 vector<int> sore(sz+1,INT_MIN); 16 for(string &s:ops) 17 { 18 if(s[0]==‘+‘) 19 { 20 sore[lastvalid]=sore[lastvalid-1]+sore[lastvalid-2]; 21 lastvalid++; 22 } 23 else if(s[0]==‘D‘) 24 { 25 sore[lastvalid]=sore[lastvalid-1]*2; 26 lastvalid++; 27 } 28 else if(s[0]==‘C‘) 29 lastvalid--; 30 else 31 sore[lastvalid++]=stoi(s); 32 } 33 return accumulate(sore.begin(),sore.begin()+lastvalid,0); 34 } 35 };
用栈或者vector都行,string转int可以直接stoi,学到了,妈个腿
标签:class ase AC pre tor win solution wing ali
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9159793.html