{"id":111763,"date":"2026-10-01T18:41:22","date_gmt":"2026-10-01T10:41:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/111763.html"},"modified":"2026-10-01T18:41:22","modified_gmt":"2026-10-01T10:41:22","slug":"c%e5%85%a5%e9%97%a8%e7%af%87%ef%bc%88%e5%8d%81%e4%ba%8c%ef%bc%89%ef%bc%9astring%ef%bc%88%e4%b8%8b%ef%bc%89-oj%e5%ae%9e%e6%88%98%e4%b8%8e%e6%89%8b%e5%86%99%e6%a8%a1%e6%8b%9f%e5%ae%9e","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/111763.html","title":{"rendered":"C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"0.1%E6%A6%82%E8%BF%B0%26%E5%BA%8F%E8%A8%80-toc\" style=\"margin-left:0px\">0.1\u6982\u8ff0&amp;\u5e8f\u8a00<\/p>\n<p id=\"%E4%B8%80%E3%80%81OJ%E5%AE%9E%E6%88%98-toc\" style=\"margin-left:0px\">\u4e00\u3001OJ\u5b9e\u6218<\/p>\n<p id=\"1.1%E4%BB%85%E4%BB%85%E5%8F%8D%E8%BD%AC%E5%AD%97%E6%AF%8D%EF%BC%88%E5%8A%9B%E6%89%A3%20917%EF%BC%89-toc\" style=\"margin-left:40px\">1.1\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd&#xff08;\u529b\u6263 917&#xff09;<\/p>\n<p id=\"1.2%E6%89%BE%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%AA%E5%87%BA%E7%8E%B0%E4%B8%80%E6%AC%A1%E7%9A%84%E5%AD%97%E7%AC%A6%EF%BC%88%E5%8A%9B%E6%89%A3%20387%EF%BC%89%EF%BC%9A-toc\" style=\"margin-left:40px\">1.2\u627e\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u5b57\u7b26&#xff08;\u529b\u6263 387&#xff09;&#xff1a;<\/p>\n<p id=\"1.3%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%87%8C%E9%9D%A2%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E5%8D%95%E8%AF%8D%E7%9A%84%E9%95%BF%E5%BA%A6%EF%BC%88%E7%89%9B%E5%AE%A2HJ1%EF%BC%89-toc\" style=\"margin-left:40px\">1.3\u5b57\u7b26\u4e32\u91cc\u9762\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6&#xff08;\u725b\u5ba2HJ1&#xff09;<\/p>\n<p id=\"1.4%E9%AA%8C%E8%AF%81%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%98%AF%E5%90%A6%E6%98%AF%E5%9B%9E%E6%96%87%EF%BC%88%E5%8A%9B%E6%89%A3125%EF%BC%89-toc\" style=\"margin-left:40px\">1.4\u9a8c\u8bc1\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u662f\u56de\u6587&#xff08;\u529b\u6263125&#xff09;<\/p>\n<p id=\"1.5%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E5%8A%A0%EF%BC%88%E5%8A%9B%E6%89%A3415%EF%BC%89-toc\" style=\"margin-left:40px\">1.5\u5b57\u7b26\u4e32\u76f8\u52a0&#xff08;\u529b\u6263415&#xff09;<\/p>\n<p id=\"1.6%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E6%95%B4%E6%95%B0atoi%EF%BC%88%E7%89%9B%E5%AE%A2%EF%BC%89-toc\" style=\"margin-left:40px\">1.6\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570atoi&#xff08;\u725b\u5ba2&#xff09;<\/p>\n<p id=\"1.7%E5%A6%82%E6%9E%9C%E5%AF%B9%E6%AD%A4%E7%B1%BB%E9%A2%98%E8%BF%98%E6%84%9F%E5%85%B4%E8%B6%A3%E7%9A%84%E8%AF%9D%EF%BC%8C%E6%AD%A4%E5%A4%84%E6%9C%89%E5%87%A0%E9%81%93%E8%AF%BE%E5%90%8E%E4%BD%9C%E4%B8%9A%EF%BC%9A-toc\" style=\"margin-left:40px\">1.7\u5982\u679c\u5bf9\u6b64\u7c7b\u9898\u8fd8\u611f\u5174\u8da3\u7684\u8bdd&#xff0c;\u6b64\u5904\u6709\u51e0\u9053\u8bfe\u540e\u4f5c\u4e1a&#xff1a;<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E6%A8%A1%E6%8B%9F%E5%AE%9E%E7%8E%B0string-toc\" style=\"margin-left:0px\">\u4e8c\u3001\u6a21\u62df\u5b9e\u73b0string<\/p>\n<p id=\"2.1%E4%B8%80%E4%B8%AA%E7%BB%8F%E5%85%B8%E7%9A%84string%E7%B1%BB%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:40px\">2.1\u4e00\u4e2a\u7ecf\u5178\u7684string\u7c7b\u95ee\u9898<\/p>\n<p id=\"2.2%E6%B5%85%E6%8B%B7%E8%B4%9D%EF%BC%9A%E4%B8%A4%E4%B8%AA%E5%AD%A9%E5%AD%90%E5%85%AC%E7%94%A8%E4%B8%80%E4%B8%AA%E7%8E%A9%E5%85%B7-toc\" style=\"margin-left:40px\">2.2\u6d45\u62f7\u8d1d&#xff1a;\u4e24\u4e2a\u5b69\u5b50\u516c\u7528\u4e00\u4e2a\u73a9\u5177<\/p>\n<p id=\"2.3%E6%B7%B1%E6%8B%B7%E8%B4%9D%EF%BC%9A%E4%BC%A0%E7%BB%9F%E7%89%88-toc\" style=\"margin-left:40px\">2.3\u6df1\u62f7\u8d1d&#xff1a;\u4f20\u7edf\u7248<\/p>\n<p id=\"2.4%E6%B7%B1%E6%8B%B7%E8%B4%9D%EF%BC%9A%E7%8E%B0%E4%BB%A3%E7%89%88%E5%86%99%E6%B3%95%EF%BC%88%E4%B8%89%E4%B8%AAswap%EF%BC%89-toc\" style=\"margin-left:40px\">2.4\u6df1\u62f7\u8d1d&#xff1a;\u73b0\u4ee3\u7248\u5199\u6cd5&#xff08;\u4e09\u4e2aswap&#xff09;<\/p>\n<p id=\"2.5%20%E5%86%99%E6%97%B6%E6%8B%B7%E8%B4%9D%EF%BC%88%E4%BA%86%E8%A7%A3%EF%BC%89-toc\" style=\"margin-left:40px\">2.5 \u5199\u65f6\u62f7\u8d1d&#xff08;\u4e86\u89e3&#xff09;<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E6%9C%80%E7%BB%88%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:0px\">\u4e09\u3001\u6700\u7ec8\u603b\u7ed3<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E8%AF%A5%E7%B3%BB%E5%88%97%E5%AF%BC%E8%88%AA%EF%BC%8C%E6%96%B9%E4%BE%BF%E8%B7%B3%E8%B7%83%E5%A4%8D%E4%B9%A0%EF%BC%9A-toc\" style=\"margin-left:0px\">\u56db\u3001\u8be5\u7cfb\u5217\u5bfc\u822a&#xff0c;\u65b9\u4fbf\u8df3\u8dc3\u590d\u4e60&#xff1a;<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"0.1%E6%A6%82%E8%BF%B0%26%E5%BA%8F%E8%A8%80\">0.1\u6982\u8ff0&amp;\u5e8f\u8a00<\/h2>\n<p>\u8fd9\u91cc\u662f\u767d\u6768&#xff0c;\u4e0a\u4e24\u7bc7\u6211\u4eec\u628astring\u7684\u63a5\u53e3\u5403\u900f\u4e86&#xff0c;\u4f20\u9001\u95e8&#xff1a;C&#043;&#043;\u5165\u95e8\u7bc7&#xff08;\u5341&#xff09;&#xff1a;string&#xff08;\u4e0a&#xff09;\u2014\u2014\u8ba4\u8bc6string&#xff1a;\u6784\u9020\u4e0e\u4e09\u5927\u904d\u5386&#xff08;\u4e00\u6761\u9f99\u8bb2\u900foperator[]\u3001\u8fed\u4ee3\u5668\u3001auto\u3001\u8303\u56f4for&#xff09;-CSDN\u535a\u5ba2C&#043;&#043;\u5165\u95e8\u7bc7&#xff08;\u5341\u4e00&#xff09;&#xff1a;string&#xff08;\u4e2d&#xff09;\u2014\u2014\u5bb9\u91cf\u4e0e\u589e\u5220\u6539\u67e5&#xff1a;\u4e00\u7bc7\u5403\u900f\u6240\u6709\u5e38\u7528\u63a5\u53e3&#xff08;\u4e07\u5b57\u8be6\u89e3&#xff09;-CSDN\u535a\u5ba2<\/p>\n<p>\u4f1a\u7528\u53ea\u662f\u7b2c\u4e00\u6b65&#xff0c;\u672c\u7bc7\u8fdb\u5165\u786c\u6838\u6a21\u5f0f&#xff1a;<\/p>\n<ul>\n<li>OJ\u5b9e\u6218&#xff1a;\u516d\u9053\u7ecf\u5178\u5b57\u7b26\u4e32\u4f53&#xff08;\u542b&#xff08;\u4e0a\u7bc7&#xff09;\u7684\u4e24\u9053\u9762\u8bd5\u9898&#xff09;&#xff0c;\u68c0\u9a8c\u4f60\u7684string\u719f\u7ec3\u5ea6\u3002<\/li>\n<li>\u6a21\u62df\u5b9e\u73b0&#xff1a;\u9762\u8bd5\u5b98\u6700\u7231\u95ee\u7684\u201c\u624b\u5199string\u7c7b\u201d\u2014\u2014\u201c\u6d45\u62f7\u8d1d\u4e3a\u4ec0\u4e48\u4f1a\u5d29&#xff0c;\u6df1\u62f7\u8d1d\u600e\u4e48\u5199&#xff0c;\u73b0\u4ee3swap\u5230\u5e95\u5999\u5728\u54ea?&#034;<\/li>\n<\/ul>\n<p>\u63a2\u672c\u6eaf\u6e90&#xff0c;\u5b66\u6709\u6240\u5f97&#xff0c;\u8ba9\u6211\u4eec\u5f00\u59cb\u5427\u3002<\/p>\n<h2 id=\"%E4%B8%80%E3%80%81OJ%E5%AE%9E%E6%88%98\">\u4e00\u3001OJ\u5b9e\u6218<\/h2>\n<h3 id=\"1.1%E4%BB%85%E4%BB%85%E5%8F%8D%E8%BD%AC%E5%AD%97%E6%AF%8D%EF%BC%88%E5%8A%9B%E6%89%A3%20917%EF%BC%89\" style=\"background-color:transparent\">1.1\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd&#xff08;\u529b\u6263 917&#xff09;<\/h3>\n<p>917. \u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/p>\n<p>\u9898\u76ee&#xff1a;\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32S&#xff0c;\u53cd\u8f6c\u5176\u4e2d\u7684\u5b57\u6bcd&#xff0c;\u975e\u5b57\u6bcd\u4fdd\u7559\u5728\u539f\u6765\u7684\u4f4d\u7f6e&#xff1a;\u5982&#xff1a;<span style=\"color:#fe2c24\">\u201ca-bC-dEf-ghIj\u201d\u2192\u201cj-Ih-gfE-dCba\u201d\u3002<\/span><\/p>\n<p><span style=\"color:#ff9900\">\u601d\u8def<\/span>&#xff1a;\u53cc\u6307\u9488&#xff0c;begin\/end\u4ece\u4e24\u7aef\u5411\u4e2d\u95f4\u8d70&#xff0c;\u9047\u5230\u975e\u5b57\u6bcd\u5c31\u8df3\u8fc7&#xff0c;\u9047\u5230\u5b57\u6bcd\u5c31\u4ea4\u6362\u3002<\/p>\n<p>class Solution {<br \/>\npublic:<br \/>\n    bool isLetter(char ch)<br \/>\n    {<br \/>\n        if (ch &gt;&#061; &#039;a&#039; &amp;&amp; ch &lt;&#061; &#039;z&#039;) return true;<br \/>\n        if (ch &gt;&#061; &#039;A&#039; &amp;&amp; ch &lt;&#061; &#039;Z&#039;) return true;<br \/>\n        return false;<br \/>\n    }<br \/>\n    string reverseOnlyLetters(string S) {<br \/>\n        if (S.empty())<br \/>\n            return S;<br \/>\n        size_t begin &#061; 0, end &#061; S.size() &#8211; 1;<br \/>\n        while (begin &lt; end)<br \/>\n        {<br \/>\n            while (begin &lt; end &amp;&amp; !isLetter(S[begin]))<br \/>\n                &#043;&#043;begin;<br \/>\n            while (begin &lt; end &amp;&amp; !isLetter(S[end]))<br \/>\n                &#8211;end;<br \/>\n            swap(S[begin], S[end]);<br \/>\n            &#043;&#043;begin;<br \/>\n            &#8211;end;<br \/>\n        }<br \/>\n        return S;<br \/>\n    }<br \/>\n}; <\/p>\n<p>\u6253\u5370\u7ed3\u679c&#xff08;\u5b9e\u6d4b&#xff09;&#xff1a;<\/p>\n<p>reverseOnlyLetters(&#034;a-bC-dEf-ghIj&#034;) &#061; j-Ih-gfE-dCba<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"720\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104118-6abe38ce02caf.png\" width=\"1464\" \/><\/p>\n<h3 id=\"1.2%E6%89%BE%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%AA%E5%87%BA%E7%8E%B0%E4%B8%80%E6%AC%A1%E7%9A%84%E5%AD%97%E7%AC%A6%EF%BC%88%E5%8A%9B%E6%89%A3%20387%EF%BC%89%EF%BC%9A\" style=\"background-color:transparent\">1.2\u627e\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u5b57\u7b26&#xff08;\u529b\u6263 387&#xff09;&#xff1a;<\/h3>\n<p>387. \u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u552f\u4e00\u5b57\u7b26 &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/p>\n<p>\u9898\u76ee&#xff1a;\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u627e\u5230\u5b83\u7684\u7b2c\u4e00\u4e2a\u4e0d\u91cd\u590d\u7684\u5b57\u7b26&#xff0c;\u8fd4\u56de\u5176\u4e0b\u6807&#xff1b;\u4e0d\u5b58\u5728\u5219\u8fd4\u56de-1\u3002\u5982<span style=\"color:#fe2c24\">\u201cloveleetcode\u201d<\/span>\u8fd4\u56de2&#xff08;\u7b2c\u4e00\u4e2a\u4e0d\u91cd\u590d\u7684\u662f\u2018v\u2019&#xff09;\u3002<\/p>\n<p><span style=\"color:#ff9900\">\u601d\u8def<\/span>&#xff1a;\u54c8\u5e0c\u8ba1\u6570\u3002\u5f00\u4e00\u4e2a256\u5927\u5c0f\u7684\u6570\u7ec4\u7edf\u8ba1\u6bcf\u4e2a\u5b57\u7b26\u51fa\u73b0\u6b21\u6570&#xff0c;\u5728\u6309\u5b57\u7b26\u6b21\u5e8f\u4ece\u524d\u5f80\u540e\u627e\u7b2c\u4e00\u4e2a\u6b21\u6570\u4e3a1\u7684\u5b57\u7b26\u3002<\/p>\n<p>class Solution {<br \/>\npublic:<br \/>\n    int firstUniqChar(string s) {<br \/>\n        int count[256] &#061; { 0 };<br \/>\n        int size &#061; s.size();<br \/>\n        for (int i &#061; 0; i &lt; size; &#043;&#043;i)<br \/>\n            count[s[i]] &#043;&#061; 1;<br \/>\n        for (int i &#061; 0; i &lt; size; &#043;&#043;i)<br \/>\n            if (1 &#061;&#061; count[s[i]])<br \/>\n                return i;<br \/>\n        return -1;<br \/>\n    }<br \/>\n}; <\/p>\n<p>\u6253\u5370\u7ed3\u679c&#xff08;\u5b9e\u6d4b&#xff09;&#xff1a;<\/p>\n<p>firstUniqChar(&#034;loveleetcode&#034;) &#061; 2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"609\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104118-6abe38ce60b98.png\" width=\"1221\" \/><\/p>\n<p>\u5047\u5982\u9762\u8bd5\u8ffd\u95ee&#xff1a;\u4e3a\u4ec0\u4e48\u7b2c\u4e8c\u904d\u4ece\u524d\u5f80\u540e\u626b&#xff0c;\u5c31\u80fd\u4fdd\u8bc1\u627e\u5230\u7684\u662f\u201c\u7b2c\u4e00\u4e2a\u4e0d\u91cd\u590d\u5b57\u7b26\u201d&#xff1f;<\/p>\n<p>\u539f\u56e0&#xff1a;\u7b2c\u4e8c\u904d\u904d\u5386\u7684\u987a\u5e8f\u5c31\u662f\u5b57\u7b26\u4e32\u539f\u987a\u5e8f&#xff0c;\u7b2c\u4e00\u4e2a\u547d\u4e2d\u201c\u8ba1\u6570\u4e3a1\u201d\u7684\u4e0b\u6807&#xff0c;\u81ea\u7136\u662f\u5168\u5c40\u7b2c\u4e00\u4e2a\u3002\u54c8\u5e0c\u94fe\u8868\u987a\u5e8f\u662f\u4e71\u7684&#xff0c;\u6240\u4ee5\u4e0d\u80fd\u76f4\u63a5\u904d\u5386\u54c8\u5e0c\u8868\u3002<\/p>\n<h3 id=\"1.3%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%87%8C%E9%9D%A2%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E5%8D%95%E8%AF%8D%E7%9A%84%E9%95%BF%E5%BA%A6%EF%BC%88%E7%89%9B%E5%AE%A2HJ1%EF%BC%89\" style=\"background-color:transparent\">1.3\u5b57\u7b26\u4e32\u91cc\u9762\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6&#xff08;\u725b\u5ba2HJ1&#xff09;<\/h3>\n<p>\u5b57\u7b26\u4e32\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6_\u725b\u5ba2\u9898\u9738_\u725b\u5ba2\u7f51<\/p>\n<p>\u9898\u76ee&#xff1a;\u8f93\u5165\u4e00\u884c\u5b57\u7b26\u4e32&#xff08;\u5355\u8bcd\u4e4b\u95f4\u53ef\u80fd\u591a\u4e2a\u7a7a\u683c&#xff09;&#xff0c;\u8f93\u51fa\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u957f\u5ea6\u3002<span style=\"color:#fe2c24\">\u5982\u201chello world\u201d\u21925\u3002<\/span><\/p>\n<p><span style=\"color:#ff9900\">\u601d\u8def<\/span>&#xff1a;\u8bfb\u4e00\u884c\u5e26\u7a7a\u683c\u7684\u5b57\u7b26\u5fc5\u987b\u7528<span style=\"color:#fe2c24\"><span style=\"background-color:#fef2f0\">getline&#xff08;<\/span><\/span>cin&gt;&gt;\u9047\u7a7a\u683c\u505c&#xff0c;&#xff08;\u4e2d\u7bc7&#xff09;7.3\u521a\u8e29\u8fc7\u8be5\u5751&#xff09;&#xff1b;\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u957f\u5ea6&#061;\u603b\u957f-\u6700\u540e\u4e00\u4e2a\u7a7a\u683c\u4e0b\u6807-1.<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    string line;<br \/>\n    while (getline(cin, line))          \/\/ \u4e0d\u8981\u7528 cin&gt;&gt;line&#xff0c;\u9047\u7a7a\u683c\u5c31\u7ed3\u675f<br \/>\n    {<br \/>\n        size_t pos &#061; line.rfind(&#039; &#039;);   \/\/ \u4ece\u540e\u5f80\u524d\u627e\u6700\u540e\u4e00\u4e2a\u7a7a\u683c<br \/>\n        cout &lt;&lt; line.size() &#8211; pos &#8211; 1 &lt;&lt; endl;<br \/>\n    }<br \/>\n    return 0;<br \/>\n} <\/p>\n<p>\u6253\u5370\u7ed3\u679c&#xff08;\u5b9e\u6d4b&#xff09;&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;hello world\u2192\u8f93\u51fa&#xff1a;5<\/p>\n<p>\u8f93\u5165&#xff1a;nowcoder\u00a0 \u2192\u8f93\u51fa&#xff1a;8<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1022\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104118-6abe38cec01b5.png\" width=\"1743\" \/><\/p>\n<h3 id=\"1.4%E9%AA%8C%E8%AF%81%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%98%AF%E5%90%A6%E6%98%AF%E5%9B%9E%E6%96%87%EF%BC%88%E5%8A%9B%E6%89%A3125%EF%BC%89\" style=\"background-color:transparent\">1.4\u9a8c\u8bc1\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u662f\u56de\u6587&#xff08;\u529b\u6263125&#xff09;<\/h3>\n<p>125. \u9a8c\u8bc1\u56de\u6587\u4e32 &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/p>\n<p>\u9898\u76ee&#xff1a;\u5224\u65ad\u5b57\u7b26\u4e32\u5728\u201c\u53ea\u8003\u8651\u5b57\u6bcd\u548c\u6570\u5b57\u3001\u5ffd\u7565\u5927\u5c0f\u5199\u201d\u540e\u662f\u4e0d\u662f\u56de\u6587\u3002\u5982<span style=\"color:#a2e043\">&#xff1a;&#034;A man, a plan, a canal: Panama&#034; \u2192 true\u3002<\/span><\/p>\n<p><span style=\"color:#ff9900\">\u601d\u8def<\/span>&#xff1a;\u5148\u628a\u5c0f\u5199\u5b57\u6bcd\u540c\u4e00\u8f6c\u5927\u5199&#xff0c;\u53cc\u6307\u9488\u4ece\u4e24\u7aef\u5411\u4e2d\u95f4\u8d70&#xff0c;\u8df3\u8fc7\u975e\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26&#xff0c;\u6bd4\u8f83\u662f\u5426\u76f8\u7b49\u3002<\/p>\n<p>\u5c0f\u8d34\u58eb&#xff1a;\u540c\u4e00\u6210\u5927\u5199\u8fd8\u662f\u5c0f\u5199\u90fd\u884c&#xff0c;\u5173\u952e\u662f\u7edf\u4e00\u2014\u2014\u5426\u5219\u2018A&#039;\u548c\u2019a\u2018\u56e0\u8be5\u76f8\u7b49\u7684\u5374\u5224false<\/p>\n<p>class Solution {<br \/>\npublic:<br \/>\n    bool isLetterOrNumber(char ch)<br \/>\n    {<br \/>\n        return (ch &gt;&#061; &#039;0&#039; &amp;&amp; ch &lt;&#061; &#039;9&#039;)<br \/>\n            || (ch &gt;&#061; &#039;a&#039; &amp;&amp; ch &lt;&#061; &#039;z&#039;)<br \/>\n            || (ch &gt;&#061; &#039;A&#039; &amp;&amp; ch &lt;&#061; &#039;Z&#039;);<br \/>\n    }<br \/>\n    bool isPalindrome(string s) {<br \/>\n        for (auto&amp; ch : s)                       \/\/ \u6ce8\u610f\u8981 auto&amp;&#xff0c;\u4fee\u6539\u539f\u5b57\u7b26\u4e32<br \/>\n        {<br \/>\n            if (ch &gt;&#061; &#039;a&#039; &amp;&amp; ch &lt;&#061; &#039;z&#039;)<br \/>\n                ch -&#061; 32;                        \/\/ \u5c0f\u5199\u8f6c\u5927\u5199<br \/>\n        }<br \/>\n        int begin &#061; 0, end &#061; s.size() &#8211; 1;<br \/>\n        while (begin &lt; end)<br \/>\n        {<br \/>\n            while (begin &lt; end &amp;&amp; !isLetterOrNumber(s[begin]))<br \/>\n                &#043;&#043;begin;<br \/>\n            while (begin &lt; end &amp;&amp; !isLetterOrNumber(s[end]))<br \/>\n                &#8211;end;<br \/>\n            if (s[begin] !&#061; s[end])<br \/>\n                return false;<br \/>\n            &#043;&#043;begin;<br \/>\n            &#8211;end;<br \/>\n        }<br \/>\n        return true;<br \/>\n    }<br \/>\n}; <\/p>\n<p>\u6253\u5370\u7ed3\u679c&#xff08;\u5b9e\u6d4b&#xff09;<\/p>\n<p>isPalindrome(&#034;A man, a plan, a canal: Panama&#034;) &#061; 1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"696\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104119-6abe38cf7b2cb.png\" width=\"1551\" \/><\/p>\n<h3 id=\"1.5%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E5%8A%A0%EF%BC%88%E5%8A%9B%E6%89%A3415%EF%BC%89\" style=\"background-color:transparent\">1.5\u5b57\u7b26\u4e32\u76f8\u52a0&#xff08;\u529b\u6263415&#xff09;<\/h3>\n<p>\u00a0\u200b\u200b\u200b\u200b\u200b\u200b415. \u5b57\u7b26\u4e32\u76f8\u52a0 &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/p>\n<p>\u9898\u76ee&#xff1a;\u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u975e\u8d1f\u6574\u6570&#xff0c;\u8fd4\u56de\u4ed6\u4eec\u7684\u548c&#xff08;\u5b57\u7b26\u4e32\u5f62\u5f0f&#xff09;\u3002\u5982\u201c<span style=\"color:#fe2c24\">456\u201d&#043;\u201c789\u201d&#061;\u201c1245\u201d\u3002<\/span><\/p>\n<p>\u8fd9\u5c31\u662f&#xff08;\u4e0a\u7bc71.3&#xff09;\u9884\u544a\u7684\u7b2c\u4e8c\u5230\u9762\u8bd5\u9898&#xff0c;\u73b0\u5728\u6765\u89e3\u51b3\u5b83\u3002<\/p>\n<p><span style=\"color:#ff9900\">\u601d\u8def<\/span>&#xff1a;\u4ece\u540e\u5f80\u524d\u9010\u4f4d\u76f8\u52a0\u3001\u5904\u7406\u8fdb\u4f4d\u3002\u7ed3\u679c\u7528&#043;&#061;\u5c3e\u63d2&#xff0c;\u6700\u540ereverse\u56de\u6765&#xff08;\u5934\u63d2insert\u4e00\u6b21\u632a\u4e00\u6b21&#xff0c;O&#xff08;n^2&#xff09;,\u522b\u7528&#xff09;\u3002<\/p>\n<p>class Solution {<br \/>\npublic:<br \/>\n    string addStrings(string num1, string num2) {<br \/>\n        int end1 &#061; num1.size() &#8211; 1;<br \/>\n        int end2 &#061; num2.size() &#8211; 1;<br \/>\n        int value1 &#061; 0, value2 &#061; 0, next &#061; 0;   \/\/ next \u662f\u8fdb\u4f4d<br \/>\n        string addret;<br \/>\n        while (end1 &gt;&#061; 0 || end2 &gt;&#061; 0)<br \/>\n        {<br \/>\n            if (end1 &gt;&#061; 0) value1 &#061; num1[end1&#8211;] &#8211; &#039;0&#039;;<br \/>\n            else           value1 &#061; 0;<br \/>\n            if (end2 &gt;&#061; 0) value2 &#061; num2[end2&#8211;] &#8211; &#039;0&#039;;<br \/>\n            else           value2 &#061; 0;<\/p>\n<p>            int valueret &#061; value1 &#043; value2 &#043; next;<br \/>\n            if (valueret &gt; 9)<br \/>\n            {<br \/>\n                next &#061; 1;<br \/>\n                valueret -&#061; 10;<br \/>\n            }<br \/>\n            else<br \/>\n            {<br \/>\n                next &#061; 0;<br \/>\n            }<br \/>\n            addret &#043;&#061; (valueret &#043; &#039;0&#039;);          \/\/ \u5c3e\u63d2&#xff0c;\u6700\u540e\u518d\u53cd\u8f6c<br \/>\n        }<br \/>\n        if (next &#061;&#061; 1)<br \/>\n            addret &#043;&#061; &#039;1&#039;;<br \/>\n        reverse(addret.begin(), addret.end());<br \/>\n        return addret;<br \/>\n    }<br \/>\n}; <\/p>\n<p>\u6253\u5370\u7ed3\u679c&#xff08;\u5b9e\u6d4b&#xff09;<\/p>\n<p>\u201c456\u201d&#043;\u201c789\u201d&#061;1245<\/p>\n<p>\u201c11\u201d&#043;\u201c123\u201d&#043;134<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"797\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104119-6abe38cfeee81.png\" width=\"1583\" \/><\/p>\n<h3 id=\"1.6%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E6%95%B4%E6%95%B0atoi%EF%BC%88%E7%89%9B%E5%AE%A2%EF%BC%89\">1.6\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570atoi&#xff08;\u725b\u5ba2&#xff09;<\/h3>\n<p>\u200b\u200b\u200b\u200b\u200b\u200b\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6574\u6570_\u725b\u5ba2\u9898\u9738_\u725b\u5ba2\u7f51<\/p>\n<p>\u8fd8\u8bb0\u5f97\u4e0a\u7bc7 1.3 \u9884\u544a\u7684\u9762\u8bd5\u9898\u5417&#xff1f;\u8fd9\u9053&#034;\u5b57\u7b26\u4e32\u8f6c\u6574\u5f62\u6570\u5b57&#034;\u5c31\u662f\u5b83\u2014\u2014\u7ecf\u5178\u4e2d\u7684\u7ecf\u5178&#xff0c;\u8fb9\u8bfb\u8fb9\u8f6c&#xff0c;\u91cd\u70b9\u5728\u8fb9\u754c\u6761\u4ef6&#xff1a;\u524d\u5bfc\u7a7a\u683c\u3001\u6b63\u8d1f\u53f7\u3001\u975e\u6570\u5b57\u5b57\u7b26\u3001\u6ea2\u51fa\u3002<\/p>\n<p><span style=\"color:#ff9900\">\u601d\u8def<\/span>&#xff1a;\u4e09\u6b65\u8d70\u2014\u2014\u8df3\u8fc7\u524d\u5bfc\u7a7a\u683c\u2192\u5904\u7406\u6b63\u8d1f\u53f7\u2192\u9010\u4f4d\u8f6c\u6362\u3002\u6ea2\u51fa\u68c0\u6d4b\u7528longlong\u4e2d\u8f6c&#xff0c;\u8d85\u8fc7int\u8303\u56f4\u76f4\u63a5\u8fd4\u56de\u8fb9\u754c\u503c\u3002<\/p>\n<p>class Solution {<br \/>\npublic:<br \/>\n    int StrToInt(string s) {<br \/>\n        int i &#061; 0, n &#061; s.size();<br \/>\n        \/\/ 1. \u8df3\u8fc7\u524d\u5bfc\u7a7a\u683c<br \/>\n        while (i &lt; n &amp;&amp; s[i] &#061;&#061; &#039; &#039;) &#043;&#043;i;<br \/>\n        \/\/ 2. \u5904\u7406\u6b63\u8d1f\u53f7<br \/>\n        int sign &#061; 1;<br \/>\n        if (i &lt; n &amp;&amp; (s[i] &#061;&#061; &#039;&#043;&#039; || s[i] &#061;&#061; &#039;-&#039;))<br \/>\n        {<br \/>\n            if (s[i] &#061;&#061; &#039;-&#039;) sign &#061; -1;<br \/>\n            &#043;&#043;i;<br \/>\n        }<br \/>\n        \/\/ 3. \u9010\u4f4d\u8f6c\u6362&#xff0c;\u540c\u65f6\u68c0\u67e5\u6ea2\u51fa<br \/>\n        long long result &#061; 0;<br \/>\n        while (i &lt; n &amp;&amp; s[i] &gt;&#061; &#039;0&#039; &amp;&amp; s[i] &lt;&#061; &#039;9&#039;)<br \/>\n        {<br \/>\n            result &#061; result * 10 &#043; (s[i] &#8211; &#039;0&#039;);<br \/>\n            if (result * sign &gt;&#061; INT_MAX) return INT_MAX;<br \/>\n            if (result * sign &lt;&#061; INT_MIN) return INT_MIN;<br \/>\n            &#043;&#043;i;<br \/>\n        }<br \/>\n        if(i&lt;n)<br \/>\n        {<br \/>\n            return 0;<br \/>\n        }<br \/>\n        return (int)(result * sign);<br \/>\n    }<br \/>\n}; <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"717\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104120-6abe38d07eff0.png\" width=\"1402\" \/><\/p>\n<h3 id=\"1.7%E5%A6%82%E6%9E%9C%E5%AF%B9%E6%AD%A4%E7%B1%BB%E9%A2%98%E8%BF%98%E6%84%9F%E5%85%B4%E8%B6%A3%E7%9A%84%E8%AF%9D%EF%BC%8C%E6%AD%A4%E5%A4%84%E6%9C%89%E5%87%A0%E9%81%93%E8%AF%BE%E5%90%8E%E4%BD%9C%E4%B8%9A%EF%BC%9A\">1.7\u5982\u679c\u5bf9\u6b64\u7c7b\u9898\u8fd8\u611f\u5174\u8da3\u7684\u8bdd&#xff0c;\u6b64\u5904\u6709\u51e0\u9053\u8bfe\u540e\u4f5c\u4e1a&#xff1a;<\/h3>\n<li>\u7ffb\u8f6c\u5b57\u7b26\u4e32 II&#xff1a;\u533a\u95f4\u90e8\u5206\u7ffb\u8f6c&#xff08;LeetCode 541&#xff09;541. \u53cd\u8f6c\u5b57\u7b26\u4e32 II &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/li>\n<li>\u7ffb\u8f6c\u5b57\u7b26\u4e32 III&#xff1a;\u7ffb\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd&#xff08;LeetCode 557&#xff09;557. \u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd III &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/li>\n<li>\u5b57\u7b26\u4e32\u76f8\u4e58&#xff08;LeetCode 43&#xff09;43. \u5b57\u7b26\u4e32\u76f8\u4e58 &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/li>\n<li>\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd\u6570&#xff08;\u725b\u5ba2&#xff09;\u627e\u51fa\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u5b57\u7b26_\u725b\u5ba2\u9898\u9738_\u725b\u5ba2\u7f51<\/li>\n<p>\u5982\u679c\u9898\u76ee\u6709\u95ee\u9898&#xff0c;\u6b22\u8fce\u5230\u8bc4\u8bba\u533a\u7559\u8a00&#xff1a;\u6211\u770b\u5230\u4f1a\u4e00\u4e00\u4e3a\u60a8\u89e3\u7b54\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2 id=\"%E4%BA%8C%E3%80%81%E6%A8%A1%E6%8B%9F%E5%AE%9E%E7%8E%B0string\">\u4e8c\u3001\u6a21\u62df\u5b9e\u73b0string<\/h2>\n<h3 id=\"2.1%E4%B8%80%E4%B8%AA%E7%BB%8F%E5%85%B8%E7%9A%84string%E7%B1%BB%E9%97%AE%E9%A2%98\">2.1\u4e00\u4e2a\u7ecf\u5178\u7684string\u7c7b\u95ee\u9898<\/h3>\n<p>\u5148\u770b\u4ee3\u7801&#xff0c;\u4f60\u89c9\u5f97\u5b83\u6709\u95ee\u9898\u5417&#xff1f;<\/p>\n<p>\/\/ \u4e3a\u4e86\u548c\u6807\u51c6\u5e93\u533a\u5206&#xff0c;\u6b64\u5904\u4f7f\u7528 String<br \/>\nclass String<br \/>\n{<br \/>\npublic:<br \/>\n    String(const char* str &#061; &#034;&#034;)<br \/>\n    {<br \/>\n        if (nullptr &#061;&#061; str)   \/\/ \u4f20\u4e86nullptr&#xff0c;\u8ba4\u4e3a\u7a0b\u5e8f\u975e\u6cd5<br \/>\n        {<br \/>\n            assert(false);<br \/>\n            return;<br \/>\n        }<br \/>\n        _str &#061; new char[strlen(str) &#043; 1];<br \/>\n        strcpy(_str, str);<br \/>\n    }<br \/>\n    ~String()<br \/>\n    {<br \/>\n        if (_str)<br \/>\n        {<br \/>\n            delete[] _str;<br \/>\n            _str &#061; nullptr;<br \/>\n        }<br \/>\n    }<br \/>\nprivate:<br \/>\n    char* _str;<br \/>\n};<\/p>\n<p>void TestString()<br \/>\n{<br \/>\n    String s1(&#034;hello bit!!!&#034;);<br \/>\n    String s2(s1);   \/\/ \u8c03\u7528\u7f16\u8bd1\u5668\u5408\u6210\u7684\u9ed8\u8ba4\u62f7\u8d1d\u6784\u9020\u2014\u2014\u6d45\u62f7\u8d1d&#xff01;<br \/>\n} <\/p>\n<p>\u5148\u8bf4\u7ed3\u8bba&#xff1a;\u6709\u95ee\u9898&#xff0c;\u800c\u4e14\u662f\u81f4\u547d\u7684\u3002<\/p>\n<p>\u8fd9\u4e2astring\u7c7b\u6ca1\u6709\u663e\u793a\u5199\u62f7\u8d1d\u6784\u9020\u548c\u8d4b\u503c\u91cd\u8f7d&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u751f\u6210\u9ed8\u8ba4\u7684\u2014\u2014\u9ed8\u8ba4\u5b9e\u73b0\u662f\u6d45\u62f7\u8d1d&#xff0c;<span style=\"color:#fe2c24\">\u4e24\u4e2a\u5bf9\u8c61\u5171\u7528\u4e00\u5757\u7a7a\u95f4&#xff0c;\u6790\u6784\u540c\u65f6\u4e00\u5757\u7a7a\u95f4\u88ab\u91ca\u653e\u4e24\u6b21&#xff0c;\u7a0b\u5e8f\u5d29\u6e83\u3002<\/span><\/p>\n<p>\u628a <span style=\"color:#fe2c24\">TestString() <\/span>\u653e\u8fdb main \u91cc\u8dd1\u4e00\u4e0b\u5c31\u77e5\u9053&#xff1a;s2 \u5148\u6790\u6784&#xff0c;\u628a\u5806\u7a7a\u95f4\u91ca\u653e\u4e86&#xff1b;s1 \u518d\u6790\u6784&#xff0c;\u53c8\u91ca\u653e\u4e00\u6b21\u540c\u4e00\u5757\u7a7a\u95f4\u2014\u2014\u91cd\u590d\u91ca\u653e&#xff0c;\u7a0b\u5e8f\u76f4\u63a5\u5d29\u6e83\u3002<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"873\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104120-6abe38d0cee4d.png\" width=\"1464\" \/><\/p>\n<p>\u9762\u8bd5\u9898&#xff1a;\u4ec0\u4e48\u6837\u7684\u7c7b\u5fc5\u987b\u663e\u793a\u5199\u62f7\u8d1d\u6784\u9020\u548c\u8d4b\u503c\u91cd\u8f7d&#xff1f;<\/p>\n<p>\u53ea\u8981\u7c7b\u4e2d\u6d89\u53ca\u8d44\u6e90\u7684\u7ba1\u7406&#xff08;\u7533\u8bf7\u4e86\u5806&#xff0c;\u6253\u5f00\u4e86\u6587\u4ef6\u7b49&#xff09;&#xff0c;\u62f7\u8d1d\u6784\u9020\u3001\u8d4b\u503c\u8fd0\u7b97\u7b26\u91cd\u8f7d\u3001\u6790\u6784\u51fd\u6570\u4e09\u4e2a\u5fc5\u987b\u663e\u793a\u7ed9\u51fa\u3002\u4eba\u4eec\u7ed9\u5b83\u53d6\u4e86\u4e00\u4e2a\u540d\u2014\u2014\u00a0Rule of Three&#xff08;\u4e09\u5927\u6cd5\u5219&#xff09;\u2014\u2014\u8981\u5199\u5c31\u4e09\u4e2a\u4e00\u8d77\u5199\u3002<\/p>\n<h3 id=\"2.2%E6%B5%85%E6%8B%B7%E8%B4%9D%EF%BC%9A%E4%B8%A4%E4%B8%AA%E5%AD%A9%E5%AD%90%E5%85%AC%E7%94%A8%E4%B8%80%E4%B8%AA%E7%8E%A9%E5%85%B7\">2.2\u6d45\u62f7\u8d1d&#xff1a;\u4e24\u4e2a\u5b69\u5b50\u516c\u7528\u4e00\u4e2a\u73a9\u5177<\/h3>\n<p>\u5148\u542c\u4e2a\u6545\u4e8b&#xff1a;<\/p>\n<p>\u4e00\u5bb6\u4e24\u4e2a\u5b69\u5b50&#xff0c;\u7236\u6bcd\u53ea\u4e70\u4e86\u4e00\u4efd\u73a9\u5177\u3002\u4e00\u8d77\u73a9\u5c31\u4e07\u4e8b\u5927\u5409&#xff1b;\u4e00\u65e6\u4e0d\u60f3\u5206\u4eab&#xff0c;\u4f60\u4e89\u6211\u593a&#xff0c;\u73a9\u5177\u5c31\u574f\u4e86\u3002<\/p>\n<p>2.1 \u91cc\u7684 s1\u3001s2 \u5c31\u662f\u8fd9\u4e48&#034;\u5171\u7528\u73a9\u5177&#034;\u7684\u2014\u2014\u6d45\u62f7\u8d1d&#xff08;\u4f4d\u62f7\u8d1d&#xff09;&#xff1a;\u7f16\u8bd1\u5668\u628a\u5bf9\u8c61\u91cc\u7684\u503c\u539f\u6837\u62f7\u8d1d\u8fc7\u53bb&#xff0c;\u6307\u9488\u6210\u5458\u53ea\u62f7\u8d1d\u4e86\u5730\u5740&#xff0c;\u4e8e\u662f\u4e24\u4e2a\u5bf9\u8c61\u5171\u4eab\u540c\u4e00\u4efd\u8d44\u6e90\u3002\u4e00\u4e2a\u5bf9\u8c61\u9500\u6bc1\u628a\u8d44\u6e90\u91ca\u653e\u4e86&#xff0c;\u53e6\u4e00\u4e2a\u8fd8\u8499\u5728\u9f13\u91cc\u7ee7\u7eed\u7528\u2014\u2014\u8bbf\u95ee\u8fdd\u89c4&#xff0c;\u5d29\u6e83\u3002<\/p>\n<p>\u6210\u5458\u53ea\u6709 int\u3001double \u8fd9\u7c7b\u666e\u901a\u503c&#xff0c;\u6d45\u62f7\u8d1d\u5b8c\u5168\u6ca1\u95ee\u9898&#xff1b;\u4e00\u65e6\u6d89\u53ca\u8d44\u6e90\u7ba1\u7406&#xff08;new \u51fa\u6765\u7684\u6307\u9488\u7b49&#xff09;&#xff0c;\u5171\u4eab\u8d44\u6e90\u5c31\u662f\u5b9a\u65f6\u70b8\u5f39\u3002<\/p>\n<h3 id=\"2.3%E6%B7%B1%E6%8B%B7%E8%B4%9D%EF%BC%9A%E4%BC%A0%E7%BB%9F%E7%89%88\">2.3\u6df1\u62f7\u8d1d&#xff1a;\u4f20\u7edf\u7248<\/h3>\n<p>\u6df1\u62f7\u8d1d&#xff1a;\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u62e5\u6709\u4e00\u4efd\u72ec\u7acb\u7684\u8d44\u6e90&#xff0c;\u4e0d\u4e0e\u5176\u4ed6\u5bf9\u8c61\u5171\u4eab\u3002\u2014\u2014\u7236\u6bcd\u7ed9\u6bcf\u4e2a\u5b69\u5b50\u5404\u81ea\u4e70\u4e00\u4efd\u73a9\u5177&#xff0c;\u5404\u73a9\u5404\u7684\u3002<\/p>\n<p>\u4f20\u7edf\u7248\u8001\u8001\u5b9e\u5b9e&#xff1a;\u5f00\u7a7a\u95f4\u2192\u62f7\u8d1d\u5185\u5bb9\u2192\u91ca\u653e\u65e7\u7a7a\u95f4\u3002\u6ce8\u610f\u8d4b\u503c\u91cd\u8f7d\u91cc\u7684\u81ea\u8d4b\u503c\u68c0\u67e5\u548c\u5148new\u540edelete&#xff1a;<\/p>\n<p>class String<br \/>\n{<br \/>\npublic:<br \/>\n    String(const char* str &#061; &#034;&#034;)<br \/>\n    {<br \/>\n        if (nullptr &#061;&#061; str)<br \/>\n        {<br \/>\n            assert(false);<br \/>\n            return;<br \/>\n        }<br \/>\n        _str &#061; new char[strlen(str) &#043; 1];<br \/>\n        strcpy(_str, str);<br \/>\n    }<\/p>\n<p>    \/\/ \u62f7\u8d1d\u6784\u9020&#xff1a;\u5f00\u65b0\u7a7a\u95f4&#xff0c;\u62f7\u8d1d\u5185\u5bb9&#xff08;\u521d\u59cb\u5316\u5217\u8868\u4e00\u6b65\u5230\u4f4d&#xff09;<br \/>\n    String(const String&amp; s)<br \/>\n        : _str(new char[strlen(s._str) &#043; 1])<br \/>\n    {<br \/>\n        strcpy(_str, s._str);<br \/>\n    }<\/p>\n<p>    \/\/ \u8d4b\u503c\u91cd\u8f7d&#xff1a;\u5148\u5f00\u597d\u65b0\u7a7a\u95f4&#xff0c;\u518d\u91ca\u653e\u65e7\u7a7a\u95f4&#xff08;\u6ce8\u610f\u81ea\u8d4b\u503c\u68c0\u67e5&#xff09;<br \/>\n    String&amp; operator&#061;(const String&amp; s)<br \/>\n    {<br \/>\n        if (this !&#061; &amp;s)    \/\/ \u9632\u6b62 s &#061; s&#xff1a;\u4e0d\u7136\u5148\u628a\u81ea\u5df1\u7684\u7a7a\u95f4\u5220\u4e86&#xff0c;\u540e\u9762\u7528\u5565&#xff1f;<br \/>\n        {<br \/>\n            char* pStr &#061; new char[strlen(s._str) &#043; 1];<br \/>\n            strcpy(pStr, s._str);<br \/>\n            delete[] _str;<br \/>\n            _str &#061; pStr;<br \/>\n        }<br \/>\n        return *this;<br \/>\n    }<\/p>\n<p>    ~String()<br \/>\n    {<br \/>\n        if (_str)<br \/>\n        {<br \/>\n            delete[] _str;<br \/>\n            _str &#061; nullptr;<br \/>\n        }<br \/>\n    }<br \/>\nprivate:<br \/>\n    char* _str;<br \/>\n}; <\/p>\n<p>\u4f20\u7edf\u7248\u7684\u4e24\u4e2a\u7ec6\u8282&#xff08;\u5e38\u88ab\u8ffd\u95ee&#xff09;&#xff1a;<\/p>\n<li>\u5148new\u540edelete&#xff1a;\u5982\u679c\u5148delete\u65e7\u7a7a\u95f4\u3001new\u65b0\u7a7a\u95f4\u53c8\u5931\u8d25\u4e86&#xff0c;\u5bf9\u8c61\u5c31\u6b8b\u5e9f\u4e86<\/li>\n<li>\u81ea\u8d4b\u503c\u68c0\u67e5&#xff1a;<span style=\"color:#fe2c24\">this!&#061;&amp;s&#xff1b;s&#061;s<\/span>\u65f6\u5982\u679c\u5148delete\u81ea\u5df1\u7a7a\u95f4&#xff0c;\u540e\u9762\u7684\u62f7\u8d1d\u5c31\u662f\u5f80\u91ce\u6307\u9488\u91cc\u5199\u3002<\/li>\n<h3 id=\"2.4%E6%B7%B1%E6%8B%B7%E8%B4%9D%EF%BC%9A%E7%8E%B0%E4%BB%A3%E7%89%88%E5%86%99%E6%B3%95%EF%BC%88%E4%B8%89%E4%B8%AAswap%EF%BC%89\">2.4\u6df1\u62f7\u8d1d&#xff1a;\u73b0\u4ee3\u7248\u5199\u6cd5&#xff08;\u4e09\u4e2aswap&#xff09;<\/h3>\n<p>\u73b0\u4ee3\u5199\u6cd5&#xff1a;\u62f7\u8d1d\u6784\u9020\u501f\u52a9\u201c\u96f6\u65f6\u5de5&#043;swap\u201d&#xff1b;\u8d4b\u503c\u91cd\u8f7d\u53c2\u6570\u7528\u4f20\u503c\u4f20\u9012&#xff0c;\u8ba9\u7f16\u8bd1\u5668\u81ea\u52a8\u8c03\u62f7\u8d1d\u6784\u9020\u751f\u6210\u4e34\u65f6\u5bf9\u8c61&#xff0c;\u518dswap\u628a\u8d44\u6e90\u6362\u8fc7\u6765\u3002\u4ee3\u7801\u91cf\u5c11\u4e00\u534a&#xff0c;\u8fd8\u4e0d\u5bb9\u6613\u5199\u9519\u3002<\/p>\n<p>class String<br \/>\n{<br \/>\npublic:<br \/>\n    String(const char* str &#061; &#034;&#034;)<br \/>\n    {<br \/>\n        if (nullptr &#061;&#061; str)<br \/>\n        {<br \/>\n            assert(false);<br \/>\n            return;<br \/>\n        }<br \/>\n        _str &#061; new char[strlen(str) &#043; 1];<br \/>\n        strcpy(_str, str);<br \/>\n    }<\/p>\n<p>    \/\/ \u62f7\u8d1d\u6784\u9020&#xff1a;swap(1)\u2014\u2014\u4e34\u65f6\u5de5\u5e72\u6d3b&#xff0c;\u8d44\u6e90\u6362\u8fc7\u6765<br \/>\n    String(const String&amp; s)<br \/>\n        : _str(nullptr)                    \/\/ \u5fc5\u987b\u5148\u7f6e\u7a7a&#xff01;\u5426\u5219swap\u540e\u4e34\u65f6\u5bf9\u8c61\u6790\u6784\u91ca\u653e\u5783\u573e\u6307\u9488<br \/>\n    {<br \/>\n        String strTmp(s._str);             \/\/ \u4e34\u65f6\u5de5&#xff1a;new &#043; strcpy<br \/>\n        swap(_str, strTmp._str);           \/\/ \u8d44\u6e90\u6362\u8fc7\u6765<br \/>\n    }                                      \/\/ strTmp \u51fa\u4f5c\u7528\u57df\u6790\u6784&#xff1a;\u91ca\u653e\u7a7a\u6307\u9488&#xff0c;\u5b89\u5168<\/p>\n<p>    \/\/ \u8d4b\u503c\u91cd\u8f7d&#xff1a;swap(2)\u2014\u2014\u503c\u4f20\u9012\u53c2\u6570&#xff0c;\u7f16\u8bd1\u5668\u81ea\u52a8\u62f7\u8d1d\u6784\u9020<br \/>\n    String&amp; operator&#061;(String s)            \/\/ s \u662f\u5b9e\u53c2\u7684\u62f7\u8d1d&#xff08;\u62f7\u8d1d\u6784\u9020\u81ea\u52a8\u8c03\u7528&#xff09;<br \/>\n    {<br \/>\n        swap(_str, s._str);                \/\/ \u4ea4\u6362\u8d44\u6e90<br \/>\n        return *this;<br \/>\n    }                                      \/\/ s \u51fa\u4f5c\u7528\u57df\u6790\u6784&#xff1a;\u987a\u5e26\u628a\u65e7\u8d44\u6e90\u91ca\u653e\u4e86<\/p>\n<p>    ~String()<br \/>\n    {<br \/>\n        if (_str)<br \/>\n        {<br \/>\n            delete[] _str;<br \/>\n            _str &#061; nullptr;<br \/>\n        }<br \/>\n    }<br \/>\nprivate:<br \/>\n    char* _str;<br \/>\n}; <\/p>\n<p>\u4e09\u4e2aswap\u9010\u4e00\u62c6\u89e3&#xff1a;&#xff08;\u89c1\u4e0a\u65b9\u4ee3\u7801\u6ce8\u91ca&#xff09;<\/p>\n<li>swap(1)\u62f7\u8d1d\u6784\u9020\u91cc\u7684swap&#xff1a;\u4e34\u65f6\u5bf9\u8c61<span style=\"color:#fe2c24\">strTmp<\/span>\u8d1f\u8d23<span style=\"color:#fe2c24\">new&#061;strcpy<\/span>&#xff08;\u8fd9\u5c31\u662f\u4e34\u65f6\u5de5&#xff09;&#xff0c;\u7136\u540e<span style=\"color:#fe2c24\">swap(_str&#xff0c;strTmp._str)<\/span>\u628a\u8d44\u6e90\u6362\u5230\u81ea\u5df1\u624b\u4e0a\u3002strTmp\u51fa\u4f5c\u7528\u57df\u81ea\u52a8\u6790\u6784\u2014\u2014\u6b64\u65f6\u5b83\u7684_str\u662f\u7a7a\u6307\u9488&#xff0c;\u6790\u6784\u5b89\u5168\u3002\u6ce8\u610f_str\u8981\u5148\u521d\u59cb\u5316\u4e3anullptr&#xff0c;\u5426\u5219swap\u4e4b\u540e\u4e34\u65f6\u5bf9\u8c61\u6790\u6784\u65f6\u91ca\u653e\u7684\u65f6\u5783\u573e\u6307\u9488\u3002<\/li>\n<li>swap(2) \u8d4b\u503c\u91cd\u8f7d\u91cc\u7684 swap&#xff1a;\u53c2\u6570\u662f\u503c\u4f20\u9012&#xff0c;\u7f16\u8bd1\u5668\u8c03\u7528\u62f7\u8d1d\u6784\u9020\u5e2e\u6211\u4eec\u751f\u6210\u4e34\u65f6\u5bf9\u8c61 s\u3002swap \u4ea4\u6362\u8d44\u6e90\u540e&#xff0c;\u51fd\u6570\u7ed3\u675f\u65f6 s \u81ea\u52a8\u6790\u6784\u2014\u2014\u987a\u5e26\u628a\u65e7\u8d44\u6e90\u91ca\u653e\u4e86\u3002\u8fde\u81ea\u8d4b\u503c\u68c0\u67e5\u90fd\u4e0d\u9700\u8981&#xff08;s &#061; s \u4e5f\u5b89\u5168&#xff09;&#xff0c;\u4f20\u7edf\u7248\u7684\u4e24\u4e2a\u5751\u5168\u907f\u5f00\u3002<\/li>\n<li>swap(3) \u5168\u5c40 swap&#xff1a;\u8fd9\u91cc\u7684 swap \u662f\u6807\u51c6\u5e93\u7684\u5168\u5c40 std::swap&#xff08;\u4ea4\u6362\u4e24\u4e2a\u6307\u9488\u7684\u503c&#xff0c;\u4ee3\u4ef7\u6781\u5c0f&#xff09;\u3002\u8fdb\u9636\u73a9\u6cd5\u662f\u81ea\u5df1\u518d\u5199\u4e00\u4e2a\u6210\u5458 swap \u51fd\u6570 &#043; \u5168\u5c40 swap \u91cd\u8f7d&#xff0c;\u9762\u8bd5\u80fd\u804a\u8fd9\u4e2a\u5c31\u662f\u52a0\u5206\u9879&#xff0c;\u7b49\u8fdb\u9636\u7bc7\u7ec6\u8bb2\u3002<\/li>\n<p>\u5bf9\u6bd4&#xff1a;\u73b0\u4ee3\u7248 vs \u4f20\u7edf\u7248&#xff0c;\u54ea\u4e2a\u597d&#xff1f;\u73b0\u4ee3\u7248\u66f4\u4f18\u96c5\u7b80\u6d01&#xff0c;\u8ddf\u4e0d\u5bb9\u6613\u51fa\u9519&#xff0c;\u800c\u4e14\u9762\u8bd5\u5199\u73b0\u4ee3\u7248\u903c\u683c\u62c9\u6ee1\u3002<\/p>\n<p>\u6253\u5370\u7ed3\u679c&#xff08;\u5b9e\u6d4b&#xff0c;VS x64&#xff0c;\u4e24\u79cd\u5199\u6cd5\u90fd\u9a8c\u8bc1\u8fc7&#xff09;&#xff1a;&#xff08;\u8fd0\u884c\u622a\u56fe\u4ec5\u5c55\u793a\u73b0\u4ee3\u5199\u6cd5\u6253\u5370\u7ed3\u679c&#xff09;<\/p>\n<p>modern: hello bit!!! | hello bit!!! | hello bit!!!\u00a0 classic: hello bit | hello bit | hello bit<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"597\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104121-6abe38d1330e6.png\" width=\"1435\" \/><\/p>\n<h3 id=\"2.5%20%E5%86%99%E6%97%B6%E6%8B%B7%E8%B4%9D%EF%BC%88%E4%BA%86%E8%A7%A3%EF%BC%89\">2.5 \u5199\u65f6\u62f7\u8d1d&#xff08;\u4e86\u89e3&#xff09;<\/h3>\n<p>\u5199\u65f6\u62f7\u8d1d\u662f\u4e00\u79cd&#034;\u62d6\u5ef6\u75c7&#034;&#xff1a;\u6d45\u62f7\u8d1d &#043; \u5f15\u7528\u8ba1\u6570\u3002 \u62f7\u8d1d\u65f6\u4e0d\u771f\u62f7\u8d1d&#xff0c;\u53ea\u5728\u67d0\u4e2a\u5bf9\u8c61\u771f\u6b63\u4fee\u6539\u6570\u636e\u65f6\u624d\u62f7\u8d1d\u3002<\/p>\n<p>\u5f15\u7528\u8ba1\u6570\u8bb0\u5f55\u8d44\u6e90\u4f7f\u7528\u8005\u7684\u4e2a\u6570&#xff1a;<\/p>\n<ul>\n<li>\u6784\u9020\u65f6\u8ba1\u6570\u7f6e1<\/li>\n<li>\u6bcf\u589e\u52a0\u4e00\u4e2a\u5bf9\u8c61\u4f7f\u7528\u8be5\u8d44\u6e90&#xff0c;\u8ba1\u6570&#043;1<\/li>\n<li>\u5bf9\u8c61\u9500\u6bc1\u65f6\u8ba1\u6570\u5148-1&#xff0c;\u51cf\u52300&#xff08;\u81ea\u5df1\u65f6\u6700\u540e\u4e00\u4e2a\u4f7f\u7528\u8005&#xff09;\u624d\u91ca\u653e\u8d44\u6e90<\/li>\n<\/ul>\n<p>\u597d\u5904\u662f\u62f7\u8d1d\u6784\u9020\u51e0\u4e4e\u96f6\u6210\u672c&#xff1b;\u574f\u5904\u662f\u5b9e\u73b0\u590d\u6742\u3001\u8ba1\u6570\u64cd\u4f5c\u6709\u7ebf\u7a0b\u5b89\u5168\u9690\u60a3\u3002\u65e7\u7248 g&#043;&#043; \u7684 string \u5c31\u662f\u5199\u65f6\u62f7\u8d1d&#xff0c;\u65b0\u7248\u672c\u5df2\u7ecf\u653e\u5f03\u4e86\u3002\u4e86\u89e3\u5373\u53ef<\/p>\n<h2 id=\"%E4%B8%89%E3%80%81%E6%9C%80%E7%BB%88%E6%80%BB%E7%BB%93\">\u4e09\u3001\u6700\u7ec8\u603b\u7ed3<\/h2>\n<li>OJ \u516d\u9053\u9898&#xff1a;\u53cc\u6307\u9488\u53cd\u8f6c\u5b57\u6bcd\u3001\u54c8\u5e0c\u8ba1\u6570\u627e\u552f\u4e00\u5b57\u7b26\u3001getline&#043;rfind \u6c42\u672b\u5355\u8bcd\u3001\u53cc\u6307\u9488\u9a8c\u56de\u6587\u3001\u8fdb\u4f4d\u6a21\u62df\u5b57\u7b26\u4e32\u76f8\u52a0\u3001\u4e09\u6b65\u8d70 atoi<\/li>\n<li>\u7c7b\u7ba1\u7406\u8d44\u6e90\u5374\u4e0d\u5199\u62f7\u8d1d\u6784\u9020\/\u8d4b\u503c\u91cd\u8f7d \u2192 \u9ed8\u8ba4\u6d45\u62f7\u8d1d \u2192 \u5171\u4eab\u8d44\u6e90 \u2192 \u91cd\u590d\u91ca\u653e \u2192 \u5d29\u6e83<\/li>\n<li>rule of Three&#xff1a;\u62f7\u8d1d\u6784\u9020\u3001\u8d4b\u503c\u91cd\u8f7d\u3001\u6790\u6784&#xff0c;\u8981\u5199\u4e09\u4e2a\u4e00\u8d77\u5199<\/li>\n<li>\u4f20\u7edf\u7248&#xff1a;\u5f00\u65b0\u7a7a\u95f4 \u2192 \u62f7\u5185\u5bb9 \u2192 \u91ca\u653e\u65e7\u7a7a\u95f4&#xff1b;\u8d4b\u503c\u91cd\u8f7d\u6ce8\u610f\u81ea\u8d4b\u503c\u68c0\u67e5\u3001\u5148 new \u540e delete<\/li>\n<li>\u73b0\u4ee3\u7248&#xff1a;\u62f7\u8d1d\u6784\u9020&#034;\u4e34\u65f6\u5de5 &#043; swap&#034;&#xff08;_str \u5fc5\u987b\u5148\u7f6e\u7a7a&#xff09;&#xff1b;\u8d4b\u503c\u91cd\u8f7d\u503c\u4f20\u9012&#xff0c;swap \u5b8c\u81ea\u52a8\u6790\u6784<\/li>\n<li>\u5199\u65f6\u62f7\u8d1d &#061; \u6d45\u62f7\u8d1d &#043; \u5f15\u7528\u8ba1\u6570&#xff0c;\u201c\u8981\u6539\u7684\u65f6\u5019\u518d\u62f7\u8d1d\u201d<\/li>\n<h2 id=\"%E5%9B%9B%E3%80%81%E8%AF%A5%E7%B3%BB%E5%88%97%E5%AF%BC%E8%88%AA%EF%BC%8C%E6%96%B9%E4%BE%BF%E8%B7%B3%E8%B7%83%E5%A4%8D%E4%B9%A0%EF%BC%9A\">\u56db\u3001\u8be5\u7cfb\u5217\u5bfc\u822a&#xff0c;\u65b9\u4fbf\u8df3\u8dc3\u590d\u4e60&#xff1a;<\/h2>\n<ul>\n<li>C&#043;&#043;\u5165\u95e8\u7bc7&#xff08;\u5341&#xff09;&#xff1a;string&#xff08;\u4e0a&#xff09;\u2014\u2014\u8ba4\u8bc6string&#xff1a;\u6784\u9020\u4e0e\u4e09\u5927\u904d\u5386&#xff08;\u4e00\u6761\u9f99\u8bb2\u900foperator[]\u3001\u8fed\u4ee3\u5668\u3001auto\u3001\u8303\u56f4for&#xff09;-CSDN\u535a\u5ba2<\/li>\n<li>C&#043;&#043;\u5165\u95e8\u7bc7&#xff08;\u5341\u4e00&#xff09;&#xff1a;string&#xff08;\u4e2d&#xff09;\u2014\u2014\u5bb9\u91cf\u4e0e\u589e\u5220\u6539\u67e5&#xff1a;\u4e00\u7bc7\u5403\u900f\u6240\u6709\u5e38\u7528\u63a5\u53e3&#xff08;\u4e07\u5b57\u8be6\u89e3&#xff09;-CSDN\u535a\u5ba2<\/li>\n<li>\u672c\u7bc7\u3002<\/li>\n<\/ul>\n<p>\u597d\u4e86&#xff0c;string \u4e09\u7bc7\u5230\u6b64\u5b8c\u7ed3&#xff01;\u4e0b\u4e00\u7bc7\u8fdb\u5165 STL \u4e0b\u4e00\u4e2a\u91cd\u91cf\u7ea7\u5bb9\u5668\u2014\u2014<span style=\"color:#fe2c24\">vector<\/span>&#xff08;\u9884\u544a&#xff1a;\u52a8\u6001\u6570\u7ec4\u3001\u8fed\u4ee3\u5668\u5931\u6548\u95ee\u9898&#xff09;\u3002\u5982\u679c\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u4e0d\u8981\u5fd8\u8bb0\u70b9\u8d5e\u4e09\u8fde\u4e00\u6ce2\u54e6&#xff01;&#xff01;&#xff01;\u6211\u662f\u767d\u6768&#xff0c;\u6211\u4eec\u4e0b\u671f\u89c1&#x1f642;\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n0.1\u6982\u8ff0&amp;\u5e8f\u8a00<br \/>\n\u4e00\u3001OJ\u5b9e\u6218<br \/>\n1.1\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd&#xff08;\u529b\u6263 917&#xff09;<br \/>\n1.2\u627e\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u5b57\u7b26&#xff08;\u529b\u6263 387&#xff09;&#xff1a;<br \/>\n1.3\u5b57\u7b26\u4e32\u91cc\u9762\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6&#xff08;\u725b\u5ba2HJ1&#xff09;<br \/>\n1.4\u9a8c\u8bc1\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u662f\u56de\u6587&#xff08;\u529b\u6263125&#xff09;<br \/>\n1.5\u5b57\u7b26\u4e32\u76f8\u52a0&#xff08;\u529b\u6263415&#xff09;<br \/>\n1.6\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570atoi&#xff08;\u725b\u5ba2&amp;<\/p>\n","protected":false},"author":2,"featured_media":111755,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11653,55,99,3759,190,176],"topic":[],"class_list":["post-111763","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-11653","tag-c","tag-java","tag-stl","tag-190","tag-176"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/111763.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 0.1\u6982\u8ff0&amp;\u5e8f\u8a00 \u4e00\u3001OJ\u5b9e\u6218 1.1\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd&#xff08;\u529b\u6263 917&#xff09; 1.2\u627e\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u5b57\u7b26&#xff08;\u529b\u6263 387&#xff09;&#xff1a; 1.3\u5b57\u7b26\u4e32\u91cc\u9762\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6&#xff08;\u725b\u5ba2HJ1&#xff09; 1.4\u9a8c\u8bc1\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u662f\u56de\u6587&#xff08;\u529b\u6263125&#xff09; 1.5\u5b57\u7b26\u4e32\u76f8\u52a0&#xff08;\u529b\u6263415&#xff09; 1.6\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570atoi&#xff08;\u725b\u5ba2&amp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/111763.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-01T10:41:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104118-6abe38ce02caf.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/111763.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/111763.html\",\"name\":\"C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-01T10:41:22+00:00\",\"dateModified\":\"2026-10-01T10:41:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/111763.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/111763.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/111763.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/111763.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 0.1\u6982\u8ff0&amp;\u5e8f\u8a00 \u4e00\u3001OJ\u5b9e\u6218 1.1\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd&#xff08;\u529b\u6263 917&#xff09; 1.2\u627e\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u5b57\u7b26&#xff08;\u529b\u6263 387&#xff09;&#xff1a; 1.3\u5b57\u7b26\u4e32\u91cc\u9762\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6&#xff08;\u725b\u5ba2HJ1&#xff09; 1.4\u9a8c\u8bc1\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u662f\u56de\u6587&#xff08;\u529b\u6263125&#xff09; 1.5\u5b57\u7b26\u4e32\u76f8\u52a0&#xff08;\u529b\u6263415&#xff09; 1.6\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570atoi&#xff08;\u725b\u5ba2&amp;","og_url":"https:\/\/www.wsisp.com\/helps\/111763.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-01T10:41:22+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001104118-6abe38ce02caf.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/111763.html","url":"https:\/\/www.wsisp.com\/helps\/111763.html","name":"C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-01T10:41:22+00:00","dateModified":"2026-10-01T10:41:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/111763.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/111763.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/111763.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u5165\u95e8\u7bc7\uff08\u5341\u4e8c\uff09\uff1astring\uff08\u4e0b\uff09\u2014\u2014OJ\u5b9e\u6218\u4e0e\u624b\u5199\u6a21\u62df\u5b9e\u73b0\uff1a\u6d45\u62f7\u8d1d\u3001\u6df1\u62f7\u8d1d\u3001\u4e09\u4e2aswap"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/111763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=111763"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/111763\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/111755"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=111763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=111763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=111763"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=111763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}