隨筆-26  評論-12  文章-0  trackbacks-0
          #include <stdio.h>
          #include <stdlib.h>

          /*判斷用戶輸入的字符串是否為回文
           *回文是指順讀和反讀都一樣的串
           *例:abccba為回文,abcdab不是回文
          */

          int Palindrome(const char *str)
          {
              int length = strlen(str);
              for(int i = 0; i <= length/2; i++)
              {
                  if(str[i] != str[length-i-1])
                  {
                      return -1;
                  }
              }
              return 1;
          }

          int main()
          {
              char s[100];
              gets(s);
              int result = Palindrome(s);
              if(result == 1)
              {
                  printf("字符串是回文");
              }
              else
              {
                  printf("字符串不是回文");
              }
          }


           
          posted on 2012-08-08 23:40 地心引力 閱讀(6390) 評論(2)  編輯  收藏

          評論:
          # re: 判斷一個字符串是否是回文 2014-10-12 12:38 | asasasas
          頂頂頂頂頂大大大大大大大大大  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 锦州市| 盱眙县| 罗定市| 罗平县| 邵阳县| 香港| 阿拉尔市| 中牟县| 宜都市| 达尔| 徐汇区| 肇州县| 孟州市| 犍为县| 黔江区| 红河县| 濮阳市| 高碑店市| 阿图什市| 镶黄旗| 科技| 威信县| 梓潼县| 永川市| 磐石市| 叶城县| 岳阳县| 杭锦后旗| 吉隆县| 信宜市| 繁昌县| 黄龙县| 福清市| 宾川县| 阿拉善左旗| 万源市| 喜德县| 观塘区| 南京市| 铅山县| 东辽县|