{"id":725,"date":"2019-11-27T13:18:35","date_gmt":"2019-11-27T13:18:35","guid":{"rendered":"http:\/\/blog.davcloud.top\/?p=725"},"modified":"2020-06-11T16:44:51","modified_gmt":"2020-06-11T16:44:51","slug":"c%ef%bc%9a%e5%86%92%e6%b3%a1%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/blog.davcloud.top\/?p=725&lang=zh","title":{"rendered":"C++\uff1a\u5192\u6ce1\u6392\u5e8f"},"content":{"rendered":"\n<h2>\u6458\u8981<\/h2>\n\n\n\n<p>\u8fd9\u7bc7\u6587\u7ae0\u5c06\u4f1a\u8bb2\u89e3\u5982\u4f55\u7528C++\u5b9e\u73b0\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5\u3002\u5c3d\u7ba1STL\u5e93\u4e2d\u5df2\u63d0\u4f9b\u4e86\u6392\u5e8f\u51fd\u6570\uff0c\u4f46\u662f\u7406\u89e3\u5982\u4f55\u901a\u8fc7\u7b80\u5355\u7684\u5faa\u73af\u5b9e\u73b0\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5\u8fd8\u662f\u6709\u5fc5\u8981\u7684\u3002<\/p>\n\n\n\n<h2>\u539f\u7406<\/h2>\n\n\n\n<p>\u5bf9\u4e8e\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5\u66f4\u7b80\u6d01\u7684\u7406\u89e3\uff0c\u53ef\u8bbf\u95ee\u7f51\u7ad9<a href=\"https:\/\/visualgo.net\/\">https:\/\/visualgo.net\/<\/a>\u3002<\/p>\n\n\n\n<h2>C++\u4ee3\u7801<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;vector>\n\nusing namespace std;\n\nint main(void)\n{\n    int temp = 0;\n    vector&lt;int> serial;\n\n    \/\/Hint sentence to ask user input numbers.\n    cout &lt;&lt; \"Please input numbers with space to seperate and finished with any non-number character:\" &lt;&lt; endl;\n\n    \/\/Use a vector as dynamic array to store numbers.\n    while(cin >> temp) serial.push_back(temp);\n\n    \/\/To sort n numbers, there are n-1 number required to be swap.\n    for(int i = 0; i &lt; serial.size()-1; i++)\n    {\n        \/\/In the swap of each number, it requred to swap n-i times.\n        for(int j = 0; j &lt; serial.size()-1-i; j++)\n        {\n            \/\/If current number is larger than next number, swap them.\n            if(serial&#91;j] > serial&#91;j+1])\n            {\n                temp = serial&#91;j];\n                serial&#91;j] = serial&#91;j+1];\n                serial&#91;j+1] = temp;\n            }\n        }\n    }\n\n    \/\/Print the result.\n    cout &lt;&lt; endl &lt;&lt; \"From min to max:\" &lt;&lt; endl;\n    for(int i = 0; i &lt; serial.size(); i++)\n        cout &lt;&lt; serial&#91;i] &lt;&lt; \" \";\n    cout &lt;&lt; endl;\n    \n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981 \u8fd9\u7bc7\u6587\u7ae0\u5c06\u4f1a\u8bb2\u89e3\u5982\u4f55\u7528C++\u5b9e\u73b0\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5\u3002\u5c3d\u7ba1STL\u5e93\u4e2d\u5df2\u63d0\u4f9b\u4e86\u6392\u5e8f\u51fd\u6570\uff0c\u4f46\u662f\u7406\u89e3\u5982\u4f55\u901a\u8fc7\u7b80\u5355\u7684\u5faa\u73af\u5b9e\u73b0\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5\u8fd8\u662f\u6709\u5fc5\u8981\u7684\u3002 \u539f\u7406 \u5bf9\u4e8e\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5\u66f4\u7b80\u6d01\u7684\u7406\u89e3\uff0c\u53ef\u8bbf\u95ee\u7f51\u7ad9https:\/\/visualgo.net\/\u3002 C++\u4ee3\u7801<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[398],"tags":[430,426],"_links":{"self":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/725"}],"collection":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=725"}],"version-history":[{"count":1,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/725\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/725\/revisions\/727"}],"wp:attachment":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}