{"id":1579,"date":"2026-05-19T15:38:22","date_gmt":"2026-05-19T07:38:22","guid":{"rendered":"http:\/\/wordpress.fangt.online\/?p=1579"},"modified":"2026-05-19T15:38:22","modified_gmt":"2026-05-19T07:38:22","slug":"%e9%ab%98%e7%b2%be%e5%ba%a6%e5%8a%a0%e6%b3%95","status":"publish","type":"post","link":"http:\/\/wordpress.fangt.online\/index.php\/2026\/05\/19\/%e9%ab%98%e7%b2%be%e5%ba%a6%e5%8a%a0%e6%b3%95\/","title":{"rendered":"\u9ad8\u7cbe\u5ea6\u52a0\u6cd5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u9ad8\u7cbe\u5ea6\u52a0\u6cd5\u5c31\u662f\u7528\u6765\u8ba1\u7b97\u4e24\u4e2a<strong>\u8fdc\u8fdc\u8d85\u8fc7<code>long long<\/code>\u8303\u56f4\u7684\u5927\u6574\u6570<\/strong>\u76f8\u52a0\u7684\u65b9\u6cd5\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u975e\u5e38\u7b80\u5355\uff1a<strong>\u6a21\u62df\u6211\u4eec\u624b\u7b97\u7ad6\u5f0f\u52a0\u6cd5<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u52a0\u6cd5\u6b65\u9aa4<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u4e24\u4e2a\u5927\u6570&nbsp;<code>A<\/code>&nbsp;\u548c&nbsp;<code>B<\/code>&nbsp;\u5df2\u7ecf\u8f6c\u6210\u4e0a\u8ff0\u7684\u5c0f\u7aef\u5e8f\u6570\u7ec4\u3002\u6211\u4eec\u505a\u52a0\u6cd5\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u4ece\u00a0<code>i = 0<\/code>\u00a0\u5f00\u59cb\uff0c\u4f9d\u6b21\u5904\u7406\u6bcf\u4e00\u4f4d\u3002<\/li>\n\n\n\n<li>\u5c06\u00a0<code>A[i] + B[i] + \u8fdb\u4f4d\u503c<\/code>\u00a0\u76f8\u52a0\uff0c\u5f97\u5230\u00a0<code>sum<\/code>\u3002<\/li>\n\n\n\n<li>\u5f53\u524d\u7ed3\u679c\u4f4d =\u00a0<code>sum % 10<\/code>\uff0c\u65b0\u7684\u8fdb\u4f4d =\u00a0<code>sum \/ 10<\/code>\u3002<\/li>\n\n\n\n<li>\u7ee7\u7eed\u5904\u7406\u4e0b\u4e00\u4f4d\uff0c\u76f4\u5230\u4e24\u4e2a\u6570\u7684\u6240\u6709\u4f4d\u90fd\u5904\u7406\u5b8c\uff0c\u5e76\u4e14\u8fdb\u4f4d\u4e3a0\u4e3a\u6b62\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u5b9e\u73b0<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;vector>\n#include &lt;string>\nusing namespace std;\n\n\/\/ \u5c06\u5b57\u7b26\u4e32\u8f6c\u4e3a\u5c0f\u7aef\u5e8f vector\nvector&lt;int> strToVec(const string &amp;s) {\n    vector&lt;int> v;\n    for (int i = s.size() - 1; i >= 0; --i)\n        v.push_back(s&#91;i] - '0');\n    return v;\n}\n\n\/\/ \u9ad8\u7cbe\u5ea6\u52a0\u6cd5\nvector&lt;int> add(const vector&lt;int> &amp;a, const vector&lt;int> &amp;b) {\n    vector&lt;int> c;\n    int carry = 0;   \/\/ \u8fdb\u4f4d\n    int i = 0;\n    \/\/ \u53ea\u8981\u8fd8\u6709\u6570\u6ca1\u52a0\u5b8c\u6216\u8005\u8fd8\u6709\u8fdb\u4f4d\uff0c\u5c31\u7ee7\u7eed\n    while (i &lt; a.size() || i &lt; b.size() || carry) {\n        int sum = carry;\n        if (i &lt; a.size()) sum += a&#91;i];\n        if (i &lt; b.size()) sum += b&#91;i];\n        c.push_back(sum % 10);   \/\/ \u5f53\u524d\u4f4d\n        carry = sum \/ 10;        \/\/ \u65b0\u7684\u8fdb\u4f4d\n        ++i;\n    }\n    return c;\n}\n\n\/\/ \u8f93\u51fa\u5927\u6570\uff08\u5c06\u5c0f\u7aef\u5e8f\u8f6c\u4e3a\u6b63\u5e38\u5b57\u7b26\u4e32\u8f93\u51fa\uff09\nvoid printVec(const vector&lt;int> &amp;v) {\n    for (int i = v.size() - 1; i >= 0; --i)\n        cout &lt;&lt; v&#91;i];\n    cout &lt;&lt; endl;\n}\n\nint main() {\n    string s1, s2;\n    cin >> s1 >> s2;\n    vector&lt;int> a = strToVec(s1);\n    vector&lt;int> b = strToVec(s2);\n    vector&lt;int> result = add(a, b);\n    printVec(result);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u6570\u636e\u8303\u56f4\uff0c\u662f\u5426\u5b58\u5728\u8d1f\u6570\u6216\u7279\u6b8a\u7b26\u53f7\uff0c\u9700\u8981\u7279\u6b8a\u5904\u7406\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9ad8\u7cbe\u5ea6\u52a0\u6cd5\u5c31\u662f\u7528\u6765\u8ba1\u7b97\u4e24\u4e2a\u8fdc\u8fdc\u8d85\u8fc7long long\u8303\u56f4\u7684\u5927\u6574\u6570\u76f8\u52a0\u7684\u65b9\u6cd5\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u975e\u5e38\u7b80\u5355\uff1a\u6a21\u62df\u6211\u4eec\u624b\u7b97 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-1579","post","type-post","status-publish","format-standard","hentry","category-zl"],"_links":{"self":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/comments?post=1579"}],"version-history":[{"count":1,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1579\/revisions"}],"predecessor-version":[{"id":1580,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1579\/revisions\/1580"}],"wp:attachment":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/media?parent=1579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/categories?post=1579"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/tags?post=1579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}