{"id":1641,"date":"2026-05-24T01:34:59","date_gmt":"2026-05-23T17:34:59","guid":{"rendered":"http:\/\/wordpress.fangt.online\/?p=1641"},"modified":"2026-05-24T01:34:59","modified_gmt":"2026-05-23T17:34:59","slug":"%e5%b8%b8%e7%94%a8%e8%87%aa%e5%ae%9a%e4%b9%89%e5%87%bd%e6%95%b0%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"http:\/\/wordpress.fangt.online\/index.php\/2026\/05\/24\/%e5%b8%b8%e7%94%a8%e8%87%aa%e5%ae%9a%e4%b9%89%e5%87%bd%e6%95%b0%e6%80%bb%e7%bb%93\/","title":{"rendered":"\u5e38\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u603b\u7ed3"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4ea4\u6362\u51fd\u6570<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\nusing namespace std;\n\n\/\/ 1. \u503c\u4f20\u9012\uff1a\u65e0\u6cd5\u4ea4\u6362\u5916\u90e8\u53d8\u91cf\nvoid swap_value(int a, int b) {\n    int temp = a;\n    a = b;\n    b = temp;\n    \/\/ \u51fd\u6570\u5185\u4ea4\u6362\u4e86\u5f62\u53c2\uff0c\u4f46\u5bf9\u5916\u90e8\u5b9e\u53c2\u65e0\u5f71\u54cd\n}\n\n\/\/ 2. \u5f15\u7528\u4f20\u9012\uff1a\u53ef\u4ee5\u76f4\u63a5\u4ea4\u6362\u5916\u90e8\u53d8\u91cf\nvoid swap_reference(int &amp;a, int &amp;b) {\n    int temp = a;\n    a = b;\n    b = temp;\n}\n\n\/\/ 3. \u5730\u5740\u4f20\u9012\uff1a\u901a\u8fc7\u6307\u9488\u4ea4\u6362\u5916\u90e8\u53d8\u91cf\nvoid swap_pointer(int *a, int *b) {\n    int temp = *a;\n    *a = *b;\n    *b = temp;\n}\n\nint main() {\n    int x = 5, y = 10;\n    \/\/ \u503c\u4f20\u9012\n    swap_value(x, y);\n    \/\/ \u5f15\u7528\u4f20\u9012\n    swap_reference(x, y);\n    \/\/ \u5730\u5740\u4f20\u9012\n    swap_pointer(&amp;x, &amp;y);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fdb\u5236\u8f6c\u6362<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5341\u8fdb\u5236\u8f6c\u4e8c\u8fdb\u5236<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string decToBin(int n) {\n    if (n == 0) return \"0\";\n    string res = \"\";\n    while (n > 0) {\n        res += (n % 2) + '0';\n        n \/= 2;\n    }\n    reverse(res.begin(), res.end());\n    return res;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int binToDec(string bin) {\n    int res = 0;\n    for (char ch : bin) {\n        res = res * 2 + (ch - '0');\n    }\n    return res;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>int binToDec(string bin) {\n    int res = 0;\n    int base = 1;                     \/\/ 2^0\n    for (int i = bin.length() - 1; i >= 0; i--) {\n        if (bin&#91;i] == '1')\n            res += base;\n        base *= 2;                    \/\/ \u4e0b\u4e00\u4f4d\u6743\u91cd\u4e582\n    }\n    return res;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5341\u8fdb\u5236\u8f6cR\u8fdb\u5236<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string decToBase(int n, int R) {\n    if (n == 0) return \"0\";\n    string res = \"\";\n    bool negative = false;\n    if (n &lt; 0) {\n        negative = true;\n        n = -n;\n    }\n    while (n > 0) {\n        int remainder = n % R;\n        if (remainder &lt; 10) {\n            res += remainder + '0';\n        } else {\n            res += (remainder - 10) + 'A';\n        }\n        n \/= R;\n    }\n    if (negative) res += '-';\n    reverse(res.begin(), res.end());\n    return res;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">R\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int baseToDec(string s, int R) {\n    int res = 0;\n    int start = 0;\n    bool negative = false;\n    string str = s;\n    if (str&#91;0] == '-') {\n        negative = true;\n        start = 1;\n    }\n    for (int i = start; i &lt; str.length(); i++) {\n        char ch = toupper(str&#91;i]);\n        int digit;\n        if (ch >= '0' &amp;&amp; ch &lt;= '9') {\n            digit = ch - '0';\n        } else {\n            digit = ch - 'A' + 10;\n        }\n        res = res * R + digit;\n    }\n    return negative ? -res : res;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5904\u7406<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5224\u65ad\u8d28\u6570\uff08\u7d20\u6570\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u57fa\u7840\u7248\nbool isPrime(int n) {\n    if (n &lt;= 1) return false;\n    for (int i = 2; i * i &lt;= n; i++) {\n        if (n % i == 0) return false;\n    }\n    return true;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4f18\u5316\u7248\nbool isPrime1(int n) {\n    if (n &lt;= 1) return false;\n    if (n == 2) return true;\n    if (n % 2 == 0) return false;\n    for (int i = 3; i * i &lt;= n; i += 2) {\n        if (n % i == 0) return false;\n    }\n    return true;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u66f4\u4f18\u7248\nbool isPrime2(int n) {\n    if (n &lt;= 1) return false;\n    if (n &lt;= 3) return true;   \/\/ 2,3 \u662f\u8d28\u6570\n    if (n % 2 == 0 || n % 3 == 0) return false;\n    \/\/ \u6240\u6709\u8d28\u6570\u90fd\u53ef\u8868\u793a\u4e3a 6k\u00b11\n    for (int i = 5; i * i &lt;= n; i += 6) {\n        if (n % i == 0 || n % (i + 2) == 0) return false;\n    }\n    return true;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5224\u65ad\u56de\u6587\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4f18\u5316\u7248\nbool isPalindrome(const string&amp; s) {\n    int left = 0, right = s.length() - 1;\n    while (left &lt; right) {\n        if (s&#91;left] != s&#91;right]) return false;\n        left++;\n        right--;\n    }\n    return true;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u7b80\u6613\u7248\nbool isPalindrome(string s) {\n    string rev = s;\n    reverse(rev.begin(), rev.end());\n    return s == rev;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u6570\u5b57\u7248\nbool isPalindrome(int n) {\n    \/\/ \u8d1f\u6570\u76f4\u63a5\u4e0d\u662f\u56de\u6587\uff08\u82e5\u8ba4\u4e3a-121\u4e0d\u662f\u56de\u6587\uff0c\u901a\u5e38\u6309\u9898\u610f\uff09\n    if (n &lt; 0) return false;\n    int original = n;\n    int reversed = 0;\n    while (n > 0) {\n        reversed = reversed * 10 + n % 10;\n        n \/= 10;\n    }\n    return original == reversed;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6570\u5b57\u5012\u5e8f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u9645\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u8fd8\u9700\u8981\u6ce8\u610f\u6570\u636e\u6b63\u8d1f\u4ee5\u53ca\u524d\u5bfc\u96f6\u60c5\u51b5\uff0c\u7075\u6d3b\u8fd0\u7528\u5b57\u7b26\u4e32\u4e0e\u6574\u6570\u4e4b\u95f4\u7684\u8f6c\u6362\u51fd\u6570\u4ee5\u53careverse\u53cd\u8f6c\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5b57\u7b26\u4e32\u5012\u5e8f\nstring reverseString(string s) {\n    string res = s;\n    int left = 0, right = res.length() - 1;\n    while (left &lt; right) {\n        swap(res&#91;left], res&#91;right]);\n        left++;\n        right--;\n    }\n    return res;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u6570\u5b57\u5012\u5e8f\nint reverseNumber(int n) {\n    bool negative = false;\n    if (n &lt; 0) {\n        negative = true;\n        n = -n;\n    }\n    int reversed = 0;\n    while (n > 0) {\n        reversed = reversed * 10 + n % 10;\n        n \/= 10;\n    }\n    return negative ? -reversed : reversed;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ea4\u6362\u51fd\u6570 \u8fdb\u5236\u8f6c\u6362 \u5341\u8fdb\u5236\u8f6c\u4e8c\u8fdb\u5236 \u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236 \u5341\u8fdb\u5236\u8f6cR\u8fdb\u5236 R\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236 \u6570\u636e\u5904\u7406 \u5224\u65ad\u8d28\u6570\uff08\u7d20\u6570\uff09 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-1641","post","type-post","status-publish","format-standard","hentry","category-zl"],"_links":{"self":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/comments?post=1641"}],"version-history":[{"count":1,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1641\/revisions"}],"predecessor-version":[{"id":1642,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1641\/revisions\/1642"}],"wp:attachment":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/media?parent=1641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/categories?post=1641"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/tags?post=1641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}