分析
典型stack
ac code
class Solution {
public:int evalRPN(vector<string>& tokens) {stack<int> s;for(auto token: tokens) {if(token &#61;&#61; "&#43;" || token &#61;&#61; "-" || token &#61;&#61; "*" || token &#61;&#61; "/") {int b &#61; s.top();s.pop();int a &#61; s.top();s.pop();int c;switch(token.c_str()[0]) {case &#39;&#43;&#39;: c &#61; a &#43; b;break;case &#39;-&#39;: c &#61; a - b;break;case &#39;*&#39;: c &#61; a * b;break;case &#39;/&#39;: c &#61; a / b;break;}s.push(c);}else {s.push(stoi(token));}}return s.top();}
};
总结
cpp中的swtich要用char或int
string转char要c_str()