{"id":392,"date":"2024-04-29T15:54:59","date_gmt":"2024-04-29T07:54:59","guid":{"rendered":"https:\/\/seanxd.com\/?p=392"},"modified":"2024-04-29T15:55:02","modified_gmt":"2024-04-29T07:55:02","slug":"zerojudge-c015","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-c015\/","title":{"rendered":"ZeroJudge C015: Reverse and Add"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 10018 &#8211; Reverse and Add<\/h4>\n\n\n\n<p class=\"\">\u628a\u4e00\u500b\u6578\u5b57\u53cd\u8f49\u4e26\u76f8\u52a0\u7684\u65b9\u6cd5\u5f88\u7c21\u55ae\uff1a\u5c31\u662f\u628a\u6578\u5b57\u53cd\u8f49\u4e26\u52a0\u4e0a\u539f\u4f86\u7684\u6578\u5b57\u3002\u5047\u5982\u9019\u500b\u548c\u4e0d\u662f\u4e00\u500b\u8ff4\u6587 (\u6307\u9019\u500b\u6578\u5b57\u5f9e\u5de6\u5230\u53f3\u548c\u5f9e\u53f3\u5230\u5de6\u90fd\u76f8\u540c\uff09\uff0c\u5c31\u4e00\u76f4\u91cd\u8907\u9019\u500b\u7a0b\u5e8f\u3002\u8209\u4f8b\u8aaa\u660e\uff1a<\/p>\n\n\n\n<p class=\"\">195 \u958b\u59cb\u7684\u6578\u5b57<br>591<br>&#8212;&#8211;<br>786<br>687<br>&#8212;&#8211;<br>1473<br>3741<br>&#8212;&#8211;<br>5214<br>4125<br>&#8212;&#8211;<br>9339 \u8ff4\u6587\u51fa\u73fe\u4e86<\/p>\n\n\n\n<p class=\"\">\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u7d93\u904e\u4e86 4 \u6b21\u76f8\u52a0\u5f8c\u5f97\u5230\u4e86\u8ff4\u6587 9339\u3002\u5e7e\u4e4e\u5c0d\u6240\u6709\u7684\u6574\u6578\u9019\u500b\u65b9\u6cd5\u90fd\u6703\u5f97\u5230\u8ff4\u6587\uff0c\u4f46\u662f\u4e5f\u6709\u6709\u8da3\u7684\u4f8b\u5916\u3002196 \u662f\u7b2c 1 \u500b\u7528\u9019\u500b\u65b9\u6cd5\u627e\u4e0d\u5230\u8ff4\u6587\u7684\u6578\u5b57\uff0c\u7136\u800c\u4e26\u6c92\u6709\u8b49\u660e\u8a72\u8ff4\u6587\u4e0d\u5b58\u5728\u3002<\/p>\n\n\n\n<p class=\"\">\u73fe\u5728\u7d66\u4f60\u4e00\u500b\u958b\u59cb\u7684\u6578\u5b57\uff0c\u4f60\u7684\u4efb\u52d9\u5c31\u662f\u6c42\u51fa\u7d93\u904e\u591a\u5c11\u6b21\u76f8\u52a0\u5f8c\uff0c\u6703\u7522\u751f\u54ea\u4e00\u500b\u8ff4\u6587\u3002\u5c0d\u6240\u6709\u7684\u6e2c\u8a66\u8cc7\u6599\uff0c\u4f60\u53ef\u4ee5\u5047\u8a2d\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li class=\"\">\u90fd\u6703\u67091\u500b\u7b54\u6848<\/li>\n\n\n\n<li class=\"\">\u57281000\u500b\u76f8\u52a0\u5167\u90fd\u6703\u5f97\u5230\u7b54\u6848<\/li>\n\n\n\n<li class=\"\">\u7522\u751f\u7684\u8ff4\u6587\u4e0d\u6703\u5927\u65bc4294967295<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u7b2c 1 \u5217\u6709\u4e00\u500b\u6574\u6578 N (0 &lt; N &lt;= 100\uff09\uff0c\u4ee3\u8868\u4ee5\u4e0b\u6709\u5e7e\u7d44\u6e2c\u8a66\u8cc7\u6599\u3002\u6bcf\u7b46\u6e2c\u8a66\u8cc7\u6599\u4e00\u5217\uff0c\u5404\u6709 1 \u500b\u6574\u6578 P\uff0c\u5c31\u662f\u958b\u59cb\u7684\u6578\u5b57\u3002<\/td><td>\u5c0d\u6bcf\u4e00\u6e2c\u8a66\u8cc7\u6599\uff0c\u8acb<strong>\u8f38\u51fa 2 \u500b\u6578\u5b57\uff1a\u5f97\u5230\u8ff4\u6587\u6240\u9700\u7684\u6700\u5c11\u6b21\u6578\u7684\u76f8\u52a0\uff0c\u4ee5\u53ca\u8a72\u8ff4\u6587<\/strong>\u3002<\/td><\/tr><tr><td>5<br>195<br>265<br>750<br>2<br>99<\/td><td>4  9339<br>5  45254<br>3  6666<br>1  4<br>6  79497<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\"><strong>\u6bcf\u500b\u6578\u5b57\u81f3\u5c11\u9700\u8981\u9032\u884c\u8a08\u7b97\u4e00\u6b21<\/strong>\uff0c\u6240\u4ee5\u5c31\u7b97<strong>\u4e00\u958b\u59cb\u5c31\u662f\u8ff4\u6587\u4e86\u4e5f\u9700\u8981\u8a08\u7b97\u4e0b\u4e00\u6b21\u51fa\u73fe\u8ff4\u6587\u7684\u6642\u9593<\/strong>\u3002\u53ef\u4ee5\u5c07\u6536\u5230\u7684\u8cc7\u6599\u8f49\u63db\u6210\u5b57\u4e32\u6216\u662f\u4e00\u958b\u59cb\u6536\u8cc7\u6599\u7684\u6642\u5019\u5c31\u6536\u6210\u5b57\u4e32\u578b\u614b\u3002\u4f7f\u7528 <strong>While\u8ff4\u5708<\/strong>\uff0c\u5982\u679c\u76ee\u524d\u7684\u6578\u5b57\u4e0d\u662f\u8ff4\u6587\u5c31\u4e00\u76f4\u505a\u8a08\u7b97\uff0c\u4e26\u4e14\u6bcf\u6b21\u9032 <strong>While\u8ff4\u5708 \u8a08\u7b97\u7684\u6b21\u6578\u5c31 +1<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=c015\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge C015: Reverse and Add<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nint toint (string str)\n{\n    if (str.length() == 1) return int(str[0] - &#39;0&#39;);\n    return stoi(str);\n}\n\nint calc (int N)\n{\n    int a = N;\n    string str = to_string(N);\n    reverse(str.begin(), str.end());\n    int b = toint(str);\n    return a + b;\n}\n\nbool OK (int N)\n{\n    string str = to_string(N);\n    string str1 = str;\n    reverse(str1.begin(), str1.end());\n    if (str == str1) return true;\n    return false;\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    cin &gt;&gt; N;\n    for (int i = 0; i&lt;N; i++)\n    {\n        int tmp;\n        cin &gt;&gt; tmp;\n        int count = 1;\n        tmp = calc(tmp);\n        while (!OK(tmp))\n        {\n            count++;\n            tmp = calc(tmp);\n        }\n        cout &lt;&lt; count &lt;&lt; &quot; &quot; &lt;&lt; tmp &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge C015\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10018 &#8211; Reverse and Add \u628a\u4e00\u500b\u6578\u5b57\u53cd\u8f49\u4e26\u76f8\u52a0\u7684\u65b9\u6cd5\u5f88\u7c21\u55ae\uff1a\u5c31 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[18],"tags":[8,11,13,12,9],"class_list":["post-392","post","type-post","status-publish","format-standard","hentry","category-uva","tag-8","tag-11","tag-13","tag-12","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":393,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/392\/revisions\/393"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}