{"id":298,"date":"2024-07-06T13:03:04","date_gmt":"2024-07-06T05:03:04","guid":{"rendered":"https:\/\/wangqianming.top\/?p=298"},"modified":"2024-07-06T13:03:04","modified_gmt":"2024-07-06T05:03:04","slug":"%e9%80%86%e6%b3%a2%e5%85%b0%e8%a1%a8%e8%be%be%e5%bc%8f%e6%b1%82%e5%80%bc","status":"publish","type":"post","link":"https:\/\/wangqianming.top\/index.php\/2024\/07\/06\/%e9%80%86%e6%b3%a2%e5%85%b0%e8%a1%a8%e8%be%be%e5%bc%8f%e6%b1%82%e5%80%bc\/","title":{"rendered":"\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c"},"content":{"rendered":"<h1>\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c<\/h1>\n<pre><code class=\"language-c\">class Solution {\npublic:\n    int evalRPN(vector&lt;string&gt;&amp; tokens) {\n        stack&lt;int&gt; stk;\n        int n = tokens.size();\n        for (int i = 0; i &lt; n; i++) {\n            string&amp; token = tokens[i];\n            if (isNumber(token)) {\n                stk.push(atoi(token.c_str()));\n            } else {\n                int num2 = stk.top();\n                stk.pop();\n                int num1 = stk.top();\n                stk.pop();\n                switch (token[0]) {\n                    case &#039;+&#039;:\n                        stk.push(num1 + num2);\n                        break;\n                    case &#039;-&#039;:\n                        stk.push(num1 - num2);\n                        break;\n                    case &#039;*&#039;:\n                        stk.push(num1 * num2);\n                        break;\n                    case &#039;\/&#039;:\n                        stk.push(num1 \/ num2);\n                        break;\n                }\n            }\n        }\n        return stk.top();\n    }\n\n    bool isNumber(string&amp; token) {\n        return !(token == &quot;+&quot; || token == &quot;-&quot; || token == &quot;*&quot; || token == &quot;\/&quot;);\n    }\n};\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c class Solution { public: int evalRPN(vector&lt;string&#038;gt &#8230","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-298","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/comments?post=298"}],"version-history":[{"count":1,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/298\/revisions"}],"predecessor-version":[{"id":299,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/298\/revisions\/299"}],"wp:attachment":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/media?parent=298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/categories?post=298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/tags?post=298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}