{"id":496,"date":"2024-05-21T09:00:00","date_gmt":"2024-05-21T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=496"},"modified":"2024-05-04T13:03:31","modified_gmt":"2024-05-04T05:03:31","slug":"zerojudge-k680","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-k680\/","title":{"rendered":"ZeroJudge K680: Adding and Subtracting Numbers"},"content":{"rendered":"\n\n\n<p class=\"\">\u80a5\u4f59\u6253\u6557\u53cd\u52a0\u6cd5\u7378\u5f8c\uff0c\u9047\u898b\u4e86 \u53cd\u6e1b\u6cd5\u7378\uff01<\/p>\n\n\n\n<p class=\"\">\u5728\u4ed6\u4ee5\u70ba\u53ea\u662f\u53cd\u6e1b\u6cd5\u7378\u800c\u5df2\u4e4b\u5f8c\uff0c\u53cd\u52a0\u6cd5\u7378\u4e5f\u4e00\u8d77\u51fa\u73fe\u4e86\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u7b2c\u4e00\u884c\u70ba\u6e2c\u8cc7\u6578\u91cf<br>\u6e2c\u8cc7\u7b2c\u4e00\u884c\u662f(+\/-)<br>\u6e2c\u8cc7\u7b2c\u4e8c\u884c\u662f\u4e00\u500b\u7b97\u5f0f<br>\u4f8b\u5982\uff1a9+9\u30015-3\u30012-9<\/td><td>\u8f38\u51fa\u70ba\u7b97\u5f0f\u7d50\u679c<\/td><\/tr><tr><td>3<br>&#8211;<br>6-5<br>+<br>6+7<br>&#8211;<br>0-3<\/td><td>1<br>13<br>-3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u4f7f\u7528\u5b57\u4e32\u4f86\u6536\u52a0\u6cd5\u7684\u7b97\u5f0f\uff0c\u8dd1\u5b57\u4e32\u7684 For\u8ff4\u5708\uff0c\u5ba3\u544a\u4e00\u500b\u7a7a\u7684\u5b57\u4e32\uff0c\u6bcf\u6b21\u90fd\u628a\u76ee\u524d\u5b57\u5143\u52a0\u5230\u7a7a\u7684\u5b57\u4e32\u4e2d\uff0c\u5982\u679c\u76ee\u524d\u5b57\u4e32\u662f\u300c+\u300d\u6216\u300c-\u300d\uff0c\u5247\u5c07\u52a0\u8d77\u4f86\u7684\u5b57\u4e32\u8f49\u6210\u6574\u6578\u4e26\u4e14\u5c07 \u5b57\u4e32.substr(\u76ee\u524d\u4f4d\u7f6e +1, \u5b57\u4e32.length()) \u4e5f\u8b8a\u6210\u6574\u6578\u9032\u884c\u52a0\u6216\u6e1b\u7684\u904b\u7b97\uff0c\u6700\u5f8c\u8f38\u51fa\u904b\u7b97\u7d50\u679c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=k680\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge K680: \u80a5\u4f59\u6b77\u96aa\u8a18&#8212;(\u53cd\u6578\u5b78\u57ce2)<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint toint(string str)\n{\n    if (str.length() == 1) return int(str[0] - &#39;0&#39;);\n    return stoi(str);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    cin &gt;&gt; N;\n    for (int i = 0; i&lt;N; i++)\n    {\n        char op;\n        cin &gt;&gt; op;\n        string str, tmp = &quot;&quot;;\n        cin &gt;&gt; str;\n        int ans = 0;\n        for (int j = 0; j&lt;str.length(); j++)\n        {\n            if (str[j] == op)\n            {\n                ans += toint(tmp);\n                if (op == &#39;+&#39;) ans += toint(str.substr(j+1, str.length()));\n                else ans -= toint(str.substr(j+1, str.length()));\n                break;\n            }\n            tmp += str[j];\n        }\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge K680\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u80a5\u4f59\u6253\u6557\u53cd\u52a0\u6cd5\u7378\u5f8c\uff0c\u9047\u898b\u4e86 \u53cd\u6e1b\u6cd5\u7378\uff01 \u5728\u4ed6\u4ee5\u70ba\u53ea\u662f\u53cd\u6e1b\u6cd5\u7378\u800c\u5df2\u4e4b\u5f8c\uff0c\u53cd\u52a0\u6cd5\u7378\u4e5f\u4e00\u8d77\u51fa\u73fe\u4e86\uff01 \u7bc4\u4f8b\u6e2c\u8cc7 \u7bc4\u4f8b\u8f38 [&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":[8,11,13,9],"class_list":["post-496","post","type-post","status-publish","format-standard","hentry","category-6","tag-8","tag-11","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"predecessor-version":[{"id":498,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/496\/revisions\/498"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}