{"id":293,"date":"2024-04-27T12:31:48","date_gmt":"2024-04-27T04:31:48","guid":{"rendered":"https:\/\/seanxd.com\/?p=293"},"modified":"2024-04-27T12:31:50","modified_gmt":"2024-04-27T04:31:50","slug":"zerojudge-c014","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-c014\/","title":{"rendered":"ZeroJudge C014: Primary Arithmetic"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 10035 &#8211; Primary Arithmetic<\/h4>\n\n\n\n<p class=\"\">\u5728\u5c0f\u5b78\u6642\u6211\u5011\u90fd\u505a\u904e\u52a0\u6cd5\u7684\u904b\u7b97\uff0c\u5c31\u662f\u628a 2 \u500b\u6574\u6578\u9760\u53f3\u5c0d\u9f4a\u7136\u5f8c\uff0c\u7531\u53f3\u81f3\u5de6\u4e00\u4f4d\u4e00\u4f4d\u76f8\u52a0\u3002\u5982\u679c\u76f8\u52a0\u7684\u7d50\u679c\u5927\u65bc\u7b49\u65bc10\u5c31\u6709\u9032\u4f4d (Carry) \u7684\u60c5\u6cc1\u51fa\u73fe\u3002<\/p>\n\n\n\n<p class=\"\">\u4f60\u7684\u4efb\u52d9\u5c31\u662f\u8981<strong>\u5224\u65b72\u500b\u6574\u6578\u76f8\u52a0\u6642\u7522\u751f\u4e86\u5e7e\u6b21\u9032\u4f4d\u7684\u60c5\u6cc1<\/strong>\u3002\u9019\u5c07\u5e6b\u52a9\u5c0f\u5b78\u8001\u5e2b\u5206\u6790\u52a0\u6cd5\u984c\u76ee\u7684\u96e3\u5ea6\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 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><strong>EOF<\/strong> \u8f38\u5165\uff0c\u6bcf\u4e00\u5217\u6e2c\u8a66\u8cc7\u6599\u6709 2 \u500b\u6b63\u6574\u6578\uff0c\u9577\u5ea6\u5747\u5c0f\u65bc 10 \u4f4d\u3002\u6700\u5f8c\u4e00\u5217\u6709 2 \u500b 0 \u4ee3\u8868\u8f38\u5165\u7d50\u675f\u3002<\/td><td>\u6bcf\u5217\u6e2c\u8a66\u8cc7\u6599\u8f38\u51fa\u8a72 2 \u6578\u76f8\u52a0\u6642\u7522\u751f\u591a\u5c11\u6b21\u9032\u4f4d\u3002\u6ce8\u610f\u9032\u4f4d\u8d85\u904e 1 \u6b21\u6642 operation \u8981\u52a0 s\u3002<\/td><\/tr><tr><td>123  456<br>555  555<br>123  594<br>0  0<\/td><td>No  carry  operation.<br>3  carry  operations.<br>1  carry  operation.<\/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=\"\"><strong>\u4f7f\u7528\u5b57\u4e32\u6536\u6578\u5b57<\/strong>\uff0c\u7136\u5f8c\u7528\u6700\u50b3\u7d71\u7684<strong>\u76f4\u5f0f\u4f86\u505a\u8a08\u7b97<\/strong>\uff0c\u53ef\u4ee5\u5148\u5c07\u5169\u500b<strong>\u5b57\u4e32\u505a\u53cd\u8f49<\/strong>\u9019\u6a23\u8dd1 <strong>For\u8ff4\u5708<\/strong> \u7684\u6642\u5019\u53ef\u4ee5\u5f9e\u5de6\u8dd1\u5230\u53f3\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=c014\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge C014: Primary Arithmetic<\/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;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nint toint(char a)\n{\n    return int(a - &#39;0&#39;);\n}\n\nvoid output(int ans)\n{\n    if (ans == 0) cout &lt;&lt; &quot;No carry operation.\\n&quot;;\n    else if (ans == 1) cout &lt;&lt; &quot;1 carry operation.\\n&quot;;\n    else cout &lt;&lt; ans &lt;&lt; &quot; carry operations.\\n&quot;;\n}\n\nint main() {\n    cin.sync_with_stdio(false);\n    cin.tie(nullptr);\n    int a, b;\n    while (cin &gt;&gt; a &gt;&gt; b)\n    {\n        if (a == 0 && b == 0) break;\n        else\n        {\n            if (a &gt; b) swap(a, b);\n            int count = 0;\n            string one = to_string(a);\n            string two = to_string(b);\n            reverse(one.begin(), one.end());\n            reverse(two.begin(), two.end());\n            int carry = 0, ans = 0;\n            for (int i = 0; i&lt;max(one.length(), two.length()); i++)\n            {\n                int sum = carry;\n                if(i &lt; (int) one.size()) {\n                    sum += one[i] - &#39;0&#39;;\n                }\n                if(i &lt; (int) two.size()) {\n                    sum += two[i] - &#39;0&#39;;\n                }\n                carry = (sum &gt;= 10);\n                ans += carry;\n            }\n            output(ans);\n        }\n    }\n}\n\n\/\/ZeroJudge C014\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10035 &#8211; Primary Arithmetic \u5728\u5c0f\u5b78\u6642\u6211\u5011\u90fd\u505a\u904e\u52a0\u6cd5\u7684\u904b\u7b97\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":[18],"tags":[8,11,13,12,9],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-uva","tag-8","tag-11","tag-13","tag-12","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/293","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=293"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/293\/revisions\/294"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}