{"id":207009,"date":"2025-07-08T08:30:34","date_gmt":"2025-07-08T00:30:34","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207009\/"},"modified":"2025-07-08T08:30:34","modified_gmt":"2025-07-08T00:30:34","slug":"%e6%89%93%e5%8d%b0%e6%89%80%e6%9c%89%e5%94%af%e4%b8%80%e7%9a%84%e6%95%b0%e5%ad%97%e7%bb%84%e5%90%88%e7%9a%84%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207009\/","title":{"rendered":"\u6253\u5370\u6240\u6709\u552f\u4e00\u7684\u6570\u5b57\u7ec4\u5408\u7684\u529f\u80fd"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u6253\u5370\u6240\u6709\u552f\u4e00\u7684\u6570\u5b57\u7ec4\u5408\u7684\u529f\u80fd<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 14:36:30<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>Golang\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300a\u6253\u5370\u6240\u6709\u552f\u4e00\u7684\u6570\u5b57\u7ec4\u5408\u7684\u529f\u80fd\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u4e00\u76f4\u5728\u5c1d\u8bd5\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\uff0c\u6253\u5370 1 \u4f4d\u6570\u5b57\uff080\u30011\u30012\u30013\u30014\u30015\u30016\u30017\u30018\u30019\u300110\uff09\u30012 \u4f4d\u6570\u5b57\uff0810\uff09\u7684\u6240\u6709\u552f\u4e00\u6570\u5b57\u7ec4\u5408, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, 29, 30, 32, 34 &#8230; 89) \u548c 3 \u4f4d\u6570\u5b57 (012) , 013, 014, 015, 016, 017, 018, 019, 023, 024, 025 &#8230; 789)\uff0c\u4ece 0 \u5f00\u59cb\u3002<\/p>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u5df2\u7ecf\u5199\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5e76\u4e14\u4e00\u76f4\u5728\u6d4b\u8bd5\u201cif\u201d\u548c\u201cfor\u201d\u7684\u4e0d\u540c\u4f4d\u7f6e\uff0c\u4f46\u6ca1\u6709\u6210\u529f\uff1a<\/p>\n<pre>func ncombinations(x int) {\n    if x == 3 {\n        fmt.Print(a, b, c)\n    }\n\n    if x == 2 {\n        fmt.Print(a, b)\n    }\n\n    if x == 3 {\n        fmt.Print(a)\n    }\n\n    for a := 0; a &lt; 10; a++ {\n        for b := a + 1; b &lt; 10; b++ {\n            for c := b + 1; c &lt; 10; c++ {\n            }\n        }\n    }\n}<\/pre>\n<p>\u5982\u4f55\u8ba9\u5b83\u53d1\u6325\u4f5c\u7528\u5e76\u4f18\u5316\u5b83\uff1f<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u8fd9\u91cc\u6709\u4e00\u4e2a\u7b80\u5355\u4f46\u6709\u6548\u4e14\u6613\u4e8e\u7406\u89e3\u7684\u89e3\u51b3\u65b9\u6848\u6765\u89e3\u51b3\u60a8\u7684\u95ee\u9898\uff1a<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"strconv\"\n)\n\nfunc main() {\n    nCombinations(3)\n}\n\nfunc nCombinations(input int) {\n    if input == 1 {\n        for i := 0; i &lt;= 9; i++ {\n            fmt.Println(i)\n        }\n    } else if input == 2 {\n        for i := 0; i &lt;= 99; i++ {\n            if i &lt;= 9 {\n                fmt.Println(\"0\" + strconv.Itoa(i))\n            } else {\n                fmt.Println(i)\n            }\n        }\n    } else if input == 3 {\n        for i := 0; i &lt;= 999; i++ {\n            if i &lt;= 9 {\n                fmt.Println(\"00\" + strconv.Itoa(i))\n            } else if i &lt;= 99 {\n                fmt.Println(\"0\" + strconv.Itoa(i))\n            } else {\n                fmt.Println(i)\n            }\n        }\n    } else {\n        fmt.Println(\"out of range\")\n    }\n}\n\n<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u6253\u5370\u6240\u6709\u552f\u4e00\u7684\u6570\u5b57\u7ec4\u5408\u7684\u529f\u80fd\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207009","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207009"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207009\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}