{"id":397,"date":"2019-12-22T22:23:25","date_gmt":"2019-12-22T14:23:25","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=397"},"modified":"2019-12-22T22:23:25","modified_gmt":"2019-12-22T14:23:25","slug":"pat-advanced-level-practice-1005-spell-it-right","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=397","title":{"rendered":"PAT (Advanced Level) Practice 1005 Spell It Right"},"content":{"rendered":"<p>Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.<\/p>\n<h3>Input Specification:<\/h3>\n<p>Each input file contains one test case. Each case occupies one line which contains an N (\u226410^100).<\/p>\n<h3>Output Specification:<\/h3>\n<p>For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.<\/p>\n<h3>Sample Input:<\/h3>\n<pre><code class=\"language-cpp line-numbers\">12345\n<\/code><\/pre>\n<h3>Sample Output:<\/h3>\n<pre><code class=\"language-cpp line-numbers\">one five\n<\/code><\/pre>\n<h3>\u9898\u76ee\u5927\u610f<\/h3>\n<p>\u7ed9\u51fa\u4e00\u4e2a\u975e\u8d1f\u6574\u6570N(\u226410^100)\uff0c\u8ba1\u7b97\u6bcf\u4e00\u4f4d\u6570\u5b57\u4e4b\u548c\uff0c\u7136\u540e\u4f7f\u7528\u82f1\u8bed\u5355\u8bcd\u8fdb\u884c\u8f93\u51fa\u3002<\/p>\n<h3>\u9898\u76ee\u5206\u6790<\/h3>\n<p>\u4f7f\u7528\u6570\u7ec4string num[10]\u8bb0\u5f55\u82f1\u6587\u5355\u8bcd\uff0cnum[x]\u8868\u793a\u6570\u5b57x\u7684\u82f1\u6587\u5355\u8bcd\u3002\u4f7f\u7528\u5b57\u7b26\u4e32\u5904\u7406\u8f93\u5165\u7684\u6570\uff0c\u8ba1\u7b97\u51fa\u6bcf\u4f4d\u6570\u5b57\u4e4b\u548csum\u540e\uff0c\u5c06sum\u8f6c\u6210\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u8f93\u51fa\u5373\u53ef\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;\nstring num[10] = {\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"};\nint main()\n{\n    int sum = 0, i;\n    char temp[105];\n    string s;\n    cin &gt;&gt; s;\n    for (i = 0; i &lt; s.length(); i++)\n        sum += s[i] - '0';\n    sprintf(temp, \"%d\", sum);\n    s = temp;\n    for (i = 0; i &lt; s.length(); i++)\n    {\n        cout &lt;&lt; num[s[i] - '0'];\n        if (i != s.length() - 1)\n            cout &lt;&lt; \" \";\n    }\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given a non-negative integer N, your task is to compute [&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-397","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\/397","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=397"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/397\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}