判断一个字符串是否是回文

判断一个字符串是否是回文
#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("字符串不是回文");
    }
}


 


更多信息请访问 java教程网 www.itchm.com

你可能感兴趣的:(判断一个字符串是否是回文)