{"id":227,"date":"2013-04-27T19:56:46","date_gmt":"2013-04-27T11:56:46","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=227"},"modified":"2013-04-27T19:56:46","modified_gmt":"2013-04-27T11:56:46","slug":"1023-have-fun-with-numbers-20","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=227","title":{"rendered":"1023. Have Fun with Numbers (20)"},"content":{"rendered":"<p>Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!<br \/>\nNow you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.<br \/>\n<b>Input Specification:<\/b><br \/>\nEach input file contains one test case. Each case contains one positive integer with no more than 20 digits.<br \/>\n<b>Output Specification:<\/b><br \/>\nFor each test case, first print in a line &#8220;Yes&#8221; if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or &#8220;No&#8221; if not. Then in the next line, print the doubled number.<br \/>\n<b>Sample Input:<\/b><\/p>\n<pre>1234567899<\/pre>\n<p><b>Sample Output:<\/b><\/p>\n<pre>Yes\n2469135798<\/pre>\n<p>====================================<br \/>\n\u6069\u6069\uff0chaving fun&#8230;.<br \/>\n\u8fd9\u9053\u9898\u7684\u9669\u6076\u7528\u5fc3\u5728\u4e8e..<br \/>\nint\u6700\u5927\u503c 2147483647<br \/>\nlonglong \u6700\u5927\u503c 9223372036854775807<br \/>\n\u90fd\u4e0d\u6ee1\u8db320\u4f4d\u7684\u6807\u51c6&#8230;\u56e0\u6b64\u9700\u8981\u81ea\u5df1\u624b\u5de5\u505a\u4e58\u6cd5\u8ba1\u7b97~<br \/>\n\u5176\u5b9e\u4e58\u6cd5\u4e5f\u662f\u5f88\u597d\u7b97\u7684\u561b~\u55b5<br \/>\n\u8fd8\u597d\u65f6\u95f4\u7ed9\u7684\u5145\u88d5&#8230;<br \/>\n====================================<\/p>\n<pre>\n#include <iostream>\nusing namespace std;\nchar digs_in[20];\nint digs_out[30];\nshort old_nums[10];\nshort new_nums[10];\nint main()\n{\n\tcin >> digs_in;\n\t\/\/find '\u0000'\n\tint pos = 0;\n\twhile(true)\n\t{\n\t\tif(digs_in[pos++] == '\u0000')\n\t\t\tbreak;\n\t}\n\tpos--;\n\t\/\/\u624b\u5de5\u505a*2...\n\tint r = 0;\n\tint d = 0;\n\tint count = 0;\n\twhile (pos--)\n\t{\n\t\td = (int)digs_in[pos] - 0x30;  \/\/ASCII -> digit\n\t\told_nums[d] ++;\n\t\td = d << 1; \/\/d*=2\n\t\td += r;\n\t\tr = d \/ 10;\n\t\td = d % 10;\n\t\tdigs_out[count++] = d;\n\t\tnew_nums[d] ++;\n\t}\n\tif( r > 0)\n\t{\n\t\t\/\/\u6700\u9ad8\u4f4d\n\t\tdigs_out[count] = r;\n\t\tnew_nums[r] ++;\n\t}\n\telse\n\t\tcount --;\n\tbool flag = true;\n\tfor(int i=0; i<10; i++)\n\t{\n\t\tif(old_nums[i] != new_nums[i])\n\t\t{\n\t\t\tflag = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(flag)\n\t{\n\t\tcout << \"Yes\" << endl;\n\t}\n\telse\n\t{\n\t\tcout << \"No\" << endl;\n\t}\n\tfor(int i=count; i>=0; i--)\n\t\tcout << digs_out[i];\n\treturn 0;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[84],"class_list":["post-227","post","type-post","status-publish","format-standard","hentry","category-study","tag-pat"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}