{"id":1300,"date":"2024-12-08T09:00:00","date_gmt":"2024-12-08T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1300"},"modified":"2024-12-08T12:53:26","modified_gmt":"2024-12-08T04:53:26","slug":"zerojudge-f698","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-f698\/","title":{"rendered":"ZeroJudge F698: \u5f8c\u5e8f\u904b\u7b97\u5f0f\u6c42\u503c"},"content":{"rendered":"\n\n\n<p>\u5e73\u5e38\u6211\u5011\u5728\u5beb\u904b\u7b97\u5f0f\u6642\u7fd2\u6163\u4f7f\u7528\u300c\u4e2d\u5e8f\u8868\u793a\u6cd5\u300d(Infix Notation)\uff0c\u4e5f\u5c31\u662f\u628a\u904b\u7b97\u5b50\u653e\u5728\u5169\u500b\u904b\u7b97\u5143\u4e2d\u9593\uff0c\u4f8b\u5982\u300c3 + 4\u300d\u30021924 \u5e74\u4e00\u4f4d\u6ce2\u862d\u7684\u908f\u8f2f\u5b78\u5bb6 Jan \u0141ukasiewicz \u767c\u660e\u4e86\u300c\u524d\u5e8f\u8868\u793a\u6cd5\u300d(Prefix Notation)\uff0c\u5b83\u537b\u662f\u628a\u904b\u7b97\u5b50\u653e\u5728\u904b\u7b97\u5143\u7684\u524d\u9762\uff0c\u4f8b\u5982 \u300c+ 3 4\u300d\u3002<\/p>\n\n\n\n<p>\u5118\u7ba1\u524d\u5e8f\u8868\u793a\u6cd5\u4e26\u4e0d\u7b26\u5408\u4eba\u985e\u7684\u95b1\u8b80\u7fd2\u6163\uff0c\u5b83\u7684\u597d\u8655\u662f\u4e0d\u9700\u8981\u7528\u5230\u4efb\u4f55\u62ec\u865f\u5c31\u53ef\u4ee5\u6e05\u695a\u5730\u6307\u5b9a\u904b\u7b97\u7684\u9806\u5e8f\u3002\u6bd4\u5982\u8aaa\uff0c\u5728\u6211\u5011\u6163\u7528\u7684\u4e2d\u5e8f\u8868\u793a\u6cd5\u88e1\uff1a<\/p>\n\n\n\n<p>1 + 2 \u00d7 3 = 7<\/p>\n\n\n\n<p>\u56e0\u70ba\u6703\u5148\u7b97\u4e58\u9664\u518d\u7b97\u52a0\u6e1b\u3002\u5982\u679c\u4f60\u8981\u5148\u7b97\u52a0\u6e1b\u7684\u8a71\u5c31\u5f97\u4f7f\u7528\u62ec\u865f\uff1a<\/p>\n\n\n\n<p>(1 + 2) \u00d7 3 = 9<\/p>\n\n\n\n<p>\u4f46\u662f\u5982\u679c\u4f7f\u7528\u524d\u5e8f\u8868\u793a\u6cd5\u5c31\u4e0d\u9700\u8981\u62ec\u865f\u4e86\uff1a<\/p>\n\n\n\n<p>+ 1 \u00d7 2 3 = 7<br>\u00d7 + 1 2 3 = 9<\/p>\n\n\n\n<p>\u524d\u5e8f\u8868\u793a\u6cd5\u4e5f\u7a31\u4f5c\u300c\u6ce2\u862d\u8868\u793a\u6cd5\u300d(PN, Polish Notation)\u3002<\/p>\n\n\n\n<p>\u5f8c\u4f86\u7576\u96fb\u8166\u767c\u660e\u4e86\u4ee5\u5f8c\uff0c\u5de5\u7a0b\u5e2b\u5011\u767c\u73fe\u524d\u5e8f\u8868\u793a\u6cd5\u5728\u6c42\u503c\u6642\u8017\u7528\u8f03\u591a\u7684\u8a18\u61b6\u9ad4\uff0c\u65bc\u662f\u5728 1954 \u5e74 Arthur Walter Burks \u63d0\u51fa\u4e86\u300c\u5f8c\u5e8f\u8868\u793a\u6cd5\u300d\uff0c\u628a\u904b\u7b97\u5b50\u653e\u5728\u904b\u7b97\u5143\u7684\u5f8c\u9762\uff0c\u4e00\u6a23\u4e0d\u9700\u8981\u62ec\u865f\u5c31\u53ef\u4ee5\u6307\u5b9a\u4e0d\u540c\u7684\u904b\u7b97\u9806\u5e8f\uff1a<\/p>\n\n\n\n<p>1 2 3 \u00d7 + = 7<br>1 2 + 3 \u00d7 = 9<\/p>\n\n\n\n<p>\u4f46\u662f\u5b83\u53ea\u8981\u4f7f\u7528\u300c\u5806\u758a\u300d\u5c31\u53ef\u4ee5\u5f88\u7c21\u55ae\u7684\u5b8c\u6210\u6c42\u503c\u52d5\u4f5c\u3002<\/p>\n\n\n\n<p>\u5f8c\u5e8f\u8868\u793a\u6cd5\u4f7f\u7528\u5728 HP \u65bc 1970 \u53ca 1980 \u5e74\u4ee3\u6240\u63a8\u51fa\u7684\u6240\u6709\u96fb\u5b50\u8a08\u7b97\u5668\uff0c\u751a\u81f3\u65bc 2020 \u5e74\u4ee3\u7684\u67d0\u4e9b\u6a5f\u578b\u4ecd\u5728\u4f7f\u7528\u3002\u4e5f\u7528\u5728\u4e00\u4e9b\u5806\u758a\u5c0e\u5411\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u4f8b\u5982 Forth\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u5f8c\u5e8f\u8a08\u7b97\u6a5f\uff0c\u4f60\u53ef\u4ee5\u73a9\u73a9\u770b\uff1ahttp:\/\/www.alcula.com\/calculators\/rpn\/\u3002<\/p>\n\n\n\n<p>\u5f8c\u5e8f\u8868\u793a\u6cd5\u4e5f\u7a31\u4f5c\u300c\u9006\u6ce2\u862d\u8868\u793a\u6cd5\u300d(RPN, Reverse Polish Notation) \u6216\u300c\u6ce2\u862d\u5f8c\u5e8f\u8868\u793a\u6cd5\u300d(Polish Postfix Notation)\u3002<\/p>\n\n\n\n<p>\u73fe\u5728\uff0c\u8acb\u4f60\u5e6b\u4e00\u500b\u5f8c\u5e8f\u8868\u793a\u6cd5\u904b\u7b97\u5f0f\u6c42\u503c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u8f38\u5165\u53ea\u6709\u4e00\u884c\uff0c\u542b\u6709\u4e00\u500b\u5f8c\u5e8f\u904b\u7b97\u5f0f\u3002\u904b\u7b97\u5143\u70ba 32 \u4f4d\u5143\u6709\u865f\u6574\u6578\uff0c\u904b\u7b97\u5b50\u5305\u62ec +, -, *, \u53ca \/\u3002\u6240\u6709\u7684\u904b\u7b97\u5143\u53ca\u8207\u904b\u7b97\u5b50\u4e4b\u9593\u5747\u4ee5\u4e00\u500b\u7a7a\u767d\u9694\u958b\u3002\u904b\u7b97\u904e\u7a0b\u53ca\u7d50\u679c\u4e5f\u90fd\u662f 32 \u4f4d\u5143\u6709\u865f\u6574\u6578\u3002<\/td><td>\u8f38\u51fa\u8a72\u904b\u7b97\u5f0f\u6240\u6c42\u5f97\u7684\u503c\u3002<\/td><\/tr><tr><td>1 2 3 * +<\/td><td>7<\/td><\/tr><tr><td>1 2 + 3 *<\/td><td>9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528 Stack \u4f86\u5b58\u8cc7\u6599\uff0c\u4e26\u4e14\u7528\u5b57\u4e32\u7684\u65b9\u5f0f EOF \u6536\u8cc7\u6599\u3002\u7576\u6536\u5230\u6578\u5b57\u6642\u5c31\u5c07\u6578\u5b57 push \u5230 Stack \u4e2d\u3002\u7576\u6536\u5230\u7684\u4e0d\u662f\u6578\u5b57\u6642\uff0c\u5c31\u5c07 Stack \u7684\u5169\u500b top \u62ff\u51fa\u4f86\u505a\u8a08\u7b97\uff0c\u9700\u8981\u8a18\u5f97\u8981 pop\uff0c\u4e26\u4e14\u7b2c\u4e00\u500b top \u662f \u52a0\u6578 (\u6216\u6e1b\u6578\u3001\u4e58\u6578\u3001\u9664\u6578)\u3002\u904b\u7b97\u5b8c\u4e4b\u5f8c\u5c07\u7d50\u679c push \u56de stack \u4e2d\u3002\u6700\u5f8c\u61c9\u8a72 Stack \u4e2d\u53ea\u6703\u5269\u4e0b\u4e00\u500b\u6578\u5b57\uff0c\u5c07\u5176\u8f38\u51fa\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=f698\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge F698: \u5f8c\u5e8f\u904b\u7b97\u5f0f\u6c42\u503c<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;stack&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    string str;\n    stack&lt;string&gt;sb;\n    while (cin &gt;&gt; str) {\n        if (str == &quot;+&quot; || str == &quot;-&quot; || str == &quot;*&quot; || str == &quot;\/&quot;) {\n            const int b = stoi(sb.top());\n            sb.pop();\n            const int a = stoi(sb.top());\n            sb.pop();\n            if (str == &quot;+&quot;) sb.push(to_string(a + b));\n            else if (str == &quot;-&quot;) sb.push(to_string(a - b));\n            else if (str == &quot;*&quot;) sb.push(to_string(a * b));\n            else if (str == &quot;\/&quot;) sb.push(to_string(a \/ b));\n        }\n        else {\n            sb.push(str);\n        }\n    }\n    cout &lt;&lt; sb.top() &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge F698\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5e73\u5e38\u6211\u5011\u5728\u5beb\u904b\u7b97\u5f0f\u6642\u7fd2\u6163\u4f7f\u7528\u300c\u4e2d\u5e8f\u8868\u793a\u6cd5\u300d(Infix Notation)\uff0c\u4e5f\u5c31\u662f\u628a\u904b\u7b97\u5b50\u653e\u5728\u5169\u500b\u904b\u7b97\u5143\u4e2d\u9593\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[6],"tags":[54,8,11],"class_list":["post-1300","post","type-post","status-publish","format-standard","hentry","category-6","tag-stack","tag-8","tag-11"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=1300"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1300\/revisions"}],"predecessor-version":[{"id":1311,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1300\/revisions\/1311"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=1300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=1300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=1300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}