Analyzing 6-10 palindrome string (20 minutes)

This question requires write function, determine whether a given string of characters is "palindrome." The so-called "palindrome" refers to read and read backwards along the same string. Such as "XYZYX" and "xyzzyx" is a palindrome.
Interface definition function:
BOOL Palindrome (char * S);

Palindrome function determines whether the input string char * s palindrome. If it returns true, otherwise false.
Referee test sample program:
#include <stdio.h>
#include <string.h>

#define MAXN 20
typedef enum {false, true} bool;

bool palindrome( char *s );

int main()
{
char s[MAXN];

scanf("%s", s);
if ( palindrome(s)==true )
    printf("Yes\n");
else
    printf("No\n");
printf("%s\n", s);

return 0;

}

/ * Your code will be embedded here * /

Sample Input 1:
thisistrueurtsisiht

Output Sample 1:
Yes
thisistrueurtsisiht

Sample Input 2:
thisisnottrue

Output Sample 2:
No
thisisnottrue

bool palindrome( char *s )
{
    int n,i,j;
    n=strlen(s);
    for(i=0,j=n-1;i<=j;i++,j--)
    {
        if(s[i]!=s[j])
        return 0;//返回0和1代表着false和ture,原因是原代码中
    }					//typedef enum {false, true} bool;的定义为枚举类型
					//关键字为enum,类型名为bool;
    if(i>j)		//枚举型里的数就是从01234这种顺序规定的;
    return 1;

}
Published 24 original articles · won praise 2 · Views 492

Guess you like

Origin blog.csdn.net/qq_45728926/article/details/104112411