{"id":261,"date":"2017-03-17T18:15:59","date_gmt":"2017-03-17T10:15:59","guid":{"rendered":"http:\/\/www.tastestars.com\/?p=261"},"modified":"2017-03-17T18:15:59","modified_gmt":"2017-03-17T10:15:59","slug":"1198","status":"publish","type":"post","link":"https:\/\/tastestars.com\/index.php\/2017\/03\/17\/1198\/","title":{"rendered":"\u4e5d\u5ea6\u9898\u76ee1198\uff1aa+b \uff08\u9ad8\u7cbe\u5ea6\u52a0\u6cd5\uff09"},"content":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0\uff1a<br \/>\n\u5b9e\u73b0\u4e00\u4e2a\u52a0\u6cd5\u5668\uff0c\u4f7f\u5176\u80fd\u591f\u8f93\u51faa+b\u7684\u503c\u3002<br \/>\n\u8f93\u5165\uff1a<br \/>\n\u8f93\u5165\u5305\u62ec\u4e24\u4e2a\u6570a\u548cb\uff0c\u5176\u4e2da\u548cb\u7684\u4f4d\u6570\u4e0d\u8d85\u8fc71000\u4f4d\u3002<br \/>\n\u8f93\u51fa\uff1a<br \/>\n\u53ef\u80fd\u6709\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\uff0c\u5bf9\u4e8e\u6bcf\u7ec4\u6570\u636e\uff0c<br \/>\n\u8f93\u51faa+b\u7684\u503c\u3002<br \/>\n\u6837\u4f8b\u8f93\u5165\uff1a<br \/>\n2 6<br \/>\n10000000000000000000 10000000000000000000000000000000<br \/>\n\u6837\u4f8b\u8f93\u51fa\uff1a<br \/>\n8<br \/>\n10000000000010000000000000000000<\/p>\n<p>\u601d\u8def\uff1a<br \/>\n1. \u5efa\u7acb\u7ed3\u6784\u4f53\uff0c\u6210\u5458\u51fd\u6570\u6765\u521d\u59cb\u5316\u3001\u6253\u5370\u3002\u91cd\u8f7d\u8fd0\u7b97\u7b26\u3002<br \/>\n2. \u6bcf\u4e2a\u6570\u5b57\u62c6\u6210\u56db\u4e2a\u4e00\u7ec4\u7684int\u6570\u7ec4\uff0c\u5bf9\u5176\u8fdb\u884c\u64cd\u4f5c\u3002<br \/>\n3. \u6ce8\u610fcarry\u8fdb\u4f4d\u4ee5\u53casize\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:default decode:true \" >#include&lt;iostream&gt;\r\n#include&lt;stdio.h&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;math.h&gt;\r\n#include&lt;string.h&gt;\r\nusing namespace std;\r\nstruct BigInteger{\r\n    int digit[1001];\r\n    int size;\r\n    void init(){  \r\n        \/*for(int i=0;i&lt;=1000;i++){\r\n            digit[i]=0;\r\n        }*\/\r\n        memset(digit,0,sizeof(digit));\r\n    }\r\n    void set(char str[]){\r\n        int j=0;\r\n        int c=1;\r\n        int count=0;\r\n        init();\r\n        for(int i=strlen(str)-1;i&gt;=0;i--){\r\n            digit[j]+=(str[i]-'0')*c;\r\n            count++;\r\n            c*=10;\r\n            if(count==4||i==0){\r\n                c=1;\r\n                j++;\r\n                count=0;\r\n            }\r\n        }\r\n        size=--j;\r\n         \r\n    }\r\n    void ouput(){\r\n        for(int i=size;i&gt;=0;i--){\r\n            if(i==size)\r\n                printf(\"%d\",digit[i]);\r\n            else\r\n                printf(\"%04d\",digit[i]);  \/\/\u5982\u679c\u4e0d\u662f\u7b2c\u4e00\u4e2a\u9700\u8981\u88650\r\n        }\r\n        cout&lt;&lt;endl;\r\n    }\r\n    BigInteger operator + (const BigInteger &amp;A) const{ \/\/B+A,\u7075\u9b42\u5728B\r\n        BigInteger c;\r\n        c.init();\r\n        int carry=0;\r\n        c.size=0;\r\n        for(int i=0;i&lt;=A.size||i&lt;=size;i++){\r\n            int temp=A.digit[i]+digit[i]+carry;\r\n            if(temp&gt;=10000){\r\n                carry=temp\/10000;\r\n                temp%=10000;\r\n            }\r\n            else\r\n                carry=0;\r\n            c.digit[c.size++]=temp;\r\n             \r\n        }\r\n        if(carry!=0){\r\n                c.digit[c.size]=carry;\r\n        }\r\n        else\r\n            c.size--;\r\n        return c;\r\n    }\r\n}a,b,c;\r\nint main(){\r\n    char str1[1000],str2[1000];\r\n    while(cin&gt;&gt;str1&gt;&gt;str2){\r\n        a.set(str1);\r\n        b.set(str2);\r\n        BigInteger c;\r\n        c=a+b;\r\n        c.ouput();\r\n    }\r\n    return 0;\r\n}\r\n\/**************************************************************\r\n    Problem: 1198\r\n    User: WZDCJ0206\r\n    Language: C++\r\n    Result: Accepted\r\n    Time:100 ms\r\n    Memory:1532 kb\r\n****************************************************************\/\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0\uff1a \u5b9e\u73b0\u4e00\u4e2a\u52a0\u6cd5\u5668\uff0c\u4f7f\u5176\u80fd\u591f\u8f93\u51faa+b\u7684\u503c\u3002 \u8f93\u5165\uff1a \u8f93\u5165\u5305\u62ec\u4e24\u4e2a\u6570a\u548cb\uff0c\u5176\u4e2da\u548cb\u7684\u4f4d\u6570\u4e0d\u8d85\u8fc710 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-261","post","type-post","status-publish","format-standard","hentry","category-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s9Hs6X-1198","_links":{"self":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/comments?post=261"}],"version-history":[{"count":1,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/261\/revisions"}],"predecessor-version":[{"id":262,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/261\/revisions\/262"}],"wp:attachment":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/media?parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/categories?post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/tags?post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}