{"id":1448,"date":"2011-01-07T12:03:00","date_gmt":"2011-01-07T04:03:00","guid":{"rendered":""},"modified":"2013-11-23T15:18:18","modified_gmt":"2013-11-23T07:18:18","slug":"%e8%be%93%e5%87%ba%e4%bb%8e1%e5%88%b01000%e7%9a%84%e6%95%b0","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1448.html","title":{"rendered":"\u8f93\u51fa\u4ece1\u52301000\u7684\u6570"},"content":{"rendered":"<p>\u6709\u8fd9\u6837\u4e00\u4e2a\u9762\u8bd5\u9898\u2014\u2014\u8bf7\u628a\u4ece1\u52301000\u7684\u6570\u6253\u5370\u51fa\u6765\uff0c\u4f46\u4f60\u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u7684\u5faa\u73af\u8bed\u53e5\u6216\u662f\u6761\u4ef6\u8bed\u53e5\u3002\u66f4\u4e0d\u80fd\u51991000\u4e2aprintf\u6216\u662fcout\u3002\u7528C\/C++\u8bed\u8a00\u3002<\/p>\n<p>\u6211\u76f8\u4fe1\uff0c\u5927\u591a\u6570\u4eba\u4e00\u5f00\u59cb\u4f60\u53ef\u80fd\u60f3\u5230\u7684\u662f\u9012\u5f52\u7b97\u6cd5\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid f(int n){\r\n    printf(\u201c%d\\n\u201d,n);\r\n    1000-n ? f(n+1):return;\r\n}\r\n\r\nint main(){\r\nf(1);\r\n}\r\n<\/pre>\n<p>\u5f53\u7136\uff0c\u9898\u76ee\u4e2d\u8bf4\u4e86\u4e0d\u80fd\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5\uff0c\u6240\u4ee5\uff0c\u4e0a\u9762\u90a3\u79cd\u89e3\u6cd5\u7684\u4e0d\u7b26\u5408\u9898\u610f\u7684\uff0c\u56e0\u4e3a\u8fd8\u662f\u53d8\u5411\u5730\u4f7f\u7528\u4e86\u6761\u4ef6\u8868\u8fbe\u5f0f\u3002\u4e0d\u8fc7\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u522b\u7684\u65b9\u6cd5\u6765\u8ba9\u8fd9\u4e2a\u9012\u5f52\u7ec8\u6b62\uff0c\u6bd4\u5982\uff1a<\/p>\n<p>\u9664\u4ee5\u96f6\uff0c\u5f53\u7a0b\u5e8fcrash\uff0c\u5475\u5475\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid f(int n){\r\n    printf(\u201c%d\\n\u201d,n);\r\n    n\/1000-n;\r\n    f(n+1);\r\n}\r\n<\/pre>\n<p>\u8fd8\u6709\u8fd9\u6837\u9000\u51fa\u9012\u5f52\u7684\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid yesprint(int i);\r\nvoid noprint(int i);\r\n\r\ntypedef void(*fnPtr)(int);\r\nfnPtr dispatch&#x5B;] = { yesprint, noprint };\r\n\r\nvoid yesprint(int i) {\r\n    printf(\u201c%d\\n\u201d, i);\r\n    dispatch&#x5B;i \/ 1000](i + 1);\r\n}\r\n\r\nvoid noprint(int i) { \/* do nothing. *\/ }\r\n\r\nint main() {\r\n      yesprint(1);\r\n}\r\n<\/pre>\n<p>\u8fd8\u6709\u4e0b\u9762\u8fd9\u4e9b\u5404\u79cd\u5404\u6837\u7684\u89e3\u6cd5\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include&lt;stdio.h&gt;\r\n\r\n\/* prints number  i *\/\r\nvoid print1(int i) {\r\n    printf(\u201c%d\\n\u201d,i);\r\n}\r\n\r\n\/* prints 10 numbers starting from i *\/\r\nvoid print10(int i) {\r\n    print1(i);\r\n    print1(i+1);\r\n    print1(i+2);\r\n    print1(i+3);\r\n    print1(i+4);\r\n    print1(i+5);\r\n    print1(i+6);\r\n    print1(i+7);\r\n    print1(i+8);\r\n    print1(i+9);\r\n}\r\n\r\n\/* prints 100 numbers starting from i *\/\r\nvoid print100(int i) {\r\n    print10(i);\r\n    print10(i+10);\r\n    print10(i+20);\r\n    print10(i+30);\r\n    print10(i+40);\r\n    print10(i+50);\r\n    print10(i+60);\r\n    print10(i+70);\r\n    print10(i+80);\r\n    print10(i+90);\r\n}\r\n\r\n\/* prints 1000 numbers starting from i *\/\r\nvoid print1000(int i) {\r\n    print100(i);\r\n    print100(i+100);\r\n    print100(i+200);\r\n    print100(i+300);\r\n    print100(i+400);\r\n    print100(i+500);\r\n    print100(i+600);\r\n    print100(i+700);\r\n    print100(i+800);\r\n    print100(i+900);\r\n}\r\n\r\nint main() {\r\n        print1000(1);\r\n        return 0;\r\n}\r\n<\/pre>\n<p>\u4e0d\u8fc7\uff0cprint\u7528\u5f97\u591a\u4e86\u4e00\u4e9b\u3002\u6211\u4eec\u53ef\u4ee5\u7528\u5b8f\u561b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include\r\n#define Out(i)       printf(\u201c%d\\n\u201d, i++);\r\n#define REP(N)       N N N N N N N N N N\r\n#define Out1000(i)   REP(REP(REP(Out(i))));\r\nvoid main()\r\n{\r\n    int i = 1;\r\n    Out1000(i);\r\n}\r\n<\/pre>\n<p>\u4e0d\u8fc7\uff0c\u6211\u4eec\u5e94\u8be5\u4f7f\u7528C++\u7684\u4e00\u4e9b\u7279\u6027\uff0c\u6bd4\u5982\uff1a<\/p>\n<p>\u4f7f\u7528\u6784\u9020\u51fd\u6570<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nclass Printer\r\n{\r\npublic:\r\n    Printer() { static unsigned i=1; cout &lt;&lt; i++ &lt;&lt; endl;; }\r\n\r\n};\r\n\r\nint main()\r\n{\r\n    Printer p&#x5B;1000];\r\n}\r\n<\/pre>\n<p>\u6216\u662f\u66f4\u4e3aNB\u7684Template\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ntemplate&lt;int N&gt;\r\nstruct NumberGeneration{\r\n    static void out(std::ostream&amp; os)\r\n    {\r\n        NumberGeneration&lt;N-1&gt;::out(os);\r\n        os &lt;&lt; N &lt;&lt; std::endl;\r\n    }\r\n};\r\n\r\ntemplate&lt;&gt;\r\nstruct NumberGeneration&lt;1&gt;{\r\n    static void out(std::ostream&amp; os)\r\n    {\r\n        os &lt;&lt; 1 &lt;&lt; std::endl;\r\n    }\r\n};\r\n\r\nint main(){\r\n    NumberGeneration&lt;1000&gt;::out(std::cout);\r\n}\r\n<\/pre>\n<p>\u6700\u540e\u6765\u4e2aBT\u4e00\u70b9\u7684\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid main(int j) {\r\n    printf(\u201c%d\\n\u201d, j);\r\n    (main + (exit \u2013 main)*(j\/1000))(j+1);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u8fd9\u6837\u4e00\u4e2a\u9762\u8bd5\u9898\u2014\u2014\u8bf7\u628a\u4ece1\u52301000\u7684\u6570\u6253\u5370\u51fa\u6765\uff0c\u4f46\u4f60\u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u7684\u5faa\u73af\u8bed\u53e5\u6216\u662f\u6761\u4ef6\u8bed\u53e5\u3002\u66f4\u4e0d\u80fd\u51991000\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1448","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1448"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1448\/revisions"}],"predecessor-version":[{"id":5159,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1448\/revisions\/5159"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}