隨筆 - 251  文章 - 504  trackbacks - 0
          <2006年11月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          本博客系個人收集材料及學(xué)習(xí)記錄之用,各類“大俠”勿擾!

          留言簿(14)

          隨筆分類

          收藏夾

          My Favorite Web Sites

          名Bloger

          非著名Bloger

          搜索

          •  

          積分與排名

          • 積分 - 202974
          • 排名 - 284

          最新評論

          ?? "回文"是指順讀和反讀內(nèi)容都相同的字符串,如:"ABCCBA".這里引入兩個指針變量,開始時,

          分別指向字符串的首末字符,當(dāng)兩個指針?biāo)缸址嗟葧r,兩指針分別向前向后移一個字符位置,

          并繼續(xù)比較,直到兩指針相遇.則說明該字符串是回文.若比較過程中,發(fā)現(xiàn)兩字符不相等,則

          可以判斷該字符串不是回文.

          代碼如下:

          /*判斷字符串是否是回文*/

          #include<stdio.h>
          #define MAX 50
          int cycle(char *s)
          {
          ? char *h,*t;
          ? for(h=s,t=s+strlen(s)-1;t>h;h++,t--)
          ? {
          ??? if(*h!=*t)
          ??? {
          ??????? printf("%c",h);
          ??????? break;
          ??? }
          ? }
          ? return t<=h;
          }

          main()
          {
          ? char s[MAX];
          ? while(1)
          ? {
          ??? puts("Please input the string you want to judge(input ^ to quit):");
          ??? 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);
          ? }
          ? puts("\nThank you for you using ,bye bye!\n");
          }

          輸出結(jié)果:

          Please input the string you want to judge(input ^ to quit):
          abcabc
          ?abcabc is not a cycle string.
          Please input the string you want to judge(input ^ to quit):
          abccba
          abccba is a cycle string.
          Please input the string you want to judge(input ^ to quit):

          ?


          ?

          posted on 2006-11-05 16:58 matthew 閱讀(4136) 評論(1)  編輯  收藏 所屬分類: 數(shù)據(jù)結(jié)構(gòu)與算法設(shè)計

          FeedBack:
          # re: C語言-判斷字符串是否回文 2007-04-19 12:46 
          看了有點思路了!謝謝你  回復(fù)  更多評論
            
          主站蜘蛛池模板: 电白县| 锦屏县| 宜川县| 专栏| 称多县| 湖北省| 延安市| 新泰市| 光泽县| 衡南县| 宁远县| 石城县| 辽阳市| 漳浦县| 三河市| 永登县| 烟台市| 陆丰市| 宁武县| 元阳县| 宜昌市| 宁陕县| 通榆县| 高州市| 富川| 黄骅市| 十堰市| 灵山县| 澳门| 江山市| 卓资县| 蚌埠市| 茂名市| 平塘县| 宜君县| 财经| 洛浦县| 七台河市| 呼玛县| 安图县| 临夏市|