<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                回文是指順讀和反讀內容均相同的字符串,例如”121”,”ABBA”,”X”等。本實例將編寫函數判斷字符串是否是回文。 引入兩個指針變量,開始時,兩個指針分別指向字符串的首末字符,當兩個指針所指字符相等時,兩個指針分別向后和向前移動一個字符位置,并繼續比較,直到兩個指針相遇,說明該字符串是回文,如果比較過程中發現兩個指針指向的字符不相等,則判斷該字符串不是回文。 下面是代碼的實現部分: ~~~ #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 20 int Cycle(char *s); /** * 回文是指順讀和反讀內容均相同的字符串,例如"121","ABBA","X"等。 * 本實例將編寫函數判斷字符串是否是回文。 * */ int main() { char s[N]; while(1){ printf("Please input the string you want to judge(input ^ to quit):\n"); scanf("%s",&s); if(s[0] == '^'){ break; } if(Cycle(s)){ printf("%s is a cycle string!\n",s); }else{ printf("%s is not a cycle string!\n",s); } } return 0; } /** * 判斷字符串s是否是回文 * * param: * char *s: 被判斷的字符串 * return: * 0: 表示字符串s不是回文數 * 非零: 表示字符串s是回文數 */ int Cycle(char *s){ char *h,*t; for(h = s,t = s + strlen(s) - 1;t > h;h++,t--) if(*h != *t) break; return t <= h; } ~~~ 下面是程序的運行結果: ![這里寫圖片描述](https://box.kancloud.cn/2016-05-24_5743c0761002e.jpg "") 在做這個實例的時候,讓我想到了之前有一個實例是判斷一個數是否是回文數,是這樣做的,假設一個數n=232,從各位數字開始,分別為2,3,2;這些數字分別乘以100,10,1最后相加,比較和原來的數是否相等,就能判斷該數書否是回文數字了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看