{"id":261,"date":"2005-12-29T08:00:00","date_gmt":"2005-12-29T08:00:00","guid":{"rendered":"https:\/\/out.cat\/?p=257"},"modified":"2005-12-29T08:00:00","modified_gmt":"2005-12-29T08:00:00","slug":"%e5%8f%a6%e5%a4%96%e4%b8%80%e9%92%9f%e6%b2%b3%e5%86%85%e5%a1%94","status":"publish","type":"post","link":"https:\/\/out.cat\/?p=261","title":{"rendered":"\u53e6\u5916\u4e00\u949f\u6cb3\u5185\u5854"},"content":{"rendered":"<p>\u611f\u89c9\u66f4\u52a0\u7b80\u6d01\uff1a\uff09<br \/>\n\/**<br \/>\n* \u6c49\u8bfa\u5854\u4e8b\u4f8b<br \/>\n* @author\uff1a\u848b\u5f6a<br \/>\n* @version 1.00 05\/10\/20<br \/>\n*\/<br \/>\nimport java.io.*;<br \/>\npublic class Towers<br \/>\n{<br \/>\nstatic int nDisks;<br \/>\npublic static void main(String[] args) throws IOException<br \/>\n{<br \/>\nSystem.out.println(&#8220;\u8bf7\u8f93\u5165\u76d8\u5b50\u7684\u4e2a\u6570\uff1a&#8221;);<br \/>\nnDisks=Integer.parseInt(In());<br \/>\ndoTowers(nDisks,&#8217;A&#8217;,&#8217;B&#8217;,&#8217;C&#8217;);<br \/>\n}<br \/>\npublic static void doTowers(int topN,char A,char B,char C)<br \/>\n{<br \/>\nif(topN==1)<br \/>\nSystem.out.println(&#8220;Disk 1 form &#8220;+A+&#8221; to &#8220;+C);<br \/>\nelse<br \/>\n{<br \/>\ndoTowers(topN-1,A,C,B);\/\/\u628aA\u4e0a\u7684N-1\u4e2a\u76d8\u5b50\u653e\u5230B\u4e0a<br \/>\nSystem.out.println(&#8220;Disk &#8220;+topN+&#8221; from &#8220;+A+&#8221; to &#8220;+C);<br \/>\ndoTowers(topN-1,B,A,C);\/\/\u628aB\u6492\u8c0e\u90a3\u4e2a\u7684N-1\u4e2a\u76d8\u5b50\u653e\u5230c\u4e0a<br \/>\n}<br \/>\n}<br \/>\npublic static String In() throws IOException<br \/>\n{<br \/>\nString str;<br \/>\nBufferedReader Input=new BufferedReader(new InputStreamReader(System.in));<br \/>\n\/\/\u6570\u636e\u6d41\u8fdb\u884c\u8f93\u5165<br \/>\nstr=Input.readLine();\/\/\u8bfb\u53d6\u884c\u3002<br \/>\nreturn str;<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u611f\u89c9\u66f4\u52a0\u7b80\u6d01\uff1a\uff09 \/** * \u6c49&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[59,62,2424],"class_list":["post-261","post","type-post","status-publish","format-standard","hentry","category-2","tag-59","tag-62","tag--java-"],"_links":{"self":[{"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/out.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=261"}],"version-history":[{"count":0,"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/posts\/261\/revisions"}],"wp:attachment":[{"href":"https:\/\/out.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/out.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/out.cat\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}