{"id":385,"date":"2019-12-21T14:19:34","date_gmt":"2019-12-21T06:19:34","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=385"},"modified":"2019-12-21T14:19:34","modified_gmt":"2019-12-21T06:19:34","slug":"pat-advanced-level-practice-1001-ab-format","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=385","title":{"rendered":"PAT (Advanced Level) Practice 1001 A+B Format"},"content":{"rendered":"<p>Calculate a+b and output the sum in standard format &#8212; that is, the digits must be separated into groups of three by commas (unless there are less than four digits).<\/p>\n<h3>Input Specification:<\/h3>\n<p>Each input file contains one test case. Each case contains a pair of integers a and b where \u221210^6 \u2264a,b\u2264 10^6.The numbers are separated by a space.<\/p>\n<h3>Output Specification:<\/h3>\n<p>For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.<\/p>\n<h3>Sample Input:<\/h3>\n<p><code>-1000000 9<\/code><\/p>\n<h3>Sample Output:<\/h3>\n<p><code>-999,991<\/code><\/p>\n<h3>\u9898\u76ee\u5927\u610f<\/h3>\n<p>\u6c42\u4e24\u6570\u4e4b\u548c\uff0c\u6309\u7167\u6bcf\u4e09\u4f4d\u4e00\u4e2a\u9017\u53f7\u7684\u683c\u5f0f\u8fdb\u884c\u8f93\u51fa\u3002<\/p>\n<h3>\u9898\u76ee\u5206\u6790<\/h3>\n<p>\u5148\u8ba1\u7b97\u4e24\u6570\u4e4b\u548c\uff0c\u518d\u8f6c\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u6309\u683c\u5f0f\u8f93\u51fa\u5373\u53ef\u3002<br \/>\n\u6ce8\u610f\uff0c\u4ece\u53f3\u5230\u5de6\u6bcf3\u4f4d\u4e00\u4e2a\u9017\u53f7\uff0c\u4e0d\u8981\u4ece\u5de6\u5230\u53f3\u3002<\/p>\n<h3>AC\u4ee3\u7801<\/h3>\n<pre><code class=\"language-cpp line-numbers\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\nint main()\n{\n    int a, b, len, i;\n    char s[20];\n    cin &gt;&gt; a &gt;&gt; b;\n    sprintf(s, \"%d\", a + b);\n    len = strlen(s);\n    for (i = 0; i &lt; len; i++)\n    {\n        cout &lt;&lt; s[i];\n        if ((len - 1 - i) % 3 == 0 &amp;&amp; i != len - 1 &amp;&amp; !(i == 0 &amp;&amp; s[i] == '-'))\n            cout &lt;&lt; \",\";\n    }\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Calculate a+b and output the sum in standard format &#038;#8 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[23,45],"class_list":["post-385","post","type-post","status-publish","format-standard","hentry","category-algo","tag-pat","tag-45"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=385"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/385\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}