回文是一种字符对称的字符串,无论从前面往后读还是从后往前读结果都一样。
// palindrome.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "string.h"
bool judgeparlindrome(const char* content)
{
bool result = true;
int length = strlen(content);
const char *front = content;
const char *rear = content + length - 1;
int index = 0;
while( index < length / 2)
{
if (*front++ != *rear--)
{
result = false;
break;
}
index++;
}
return result;
}
int _tmain(int argc, _TCHAR* argv[])
{
char content[100];
while(1)
{
printf("input a string:");
scanf("%s", content);
if (judgeparlindrome(content))
printf("yes\n");
else
printf("no\n");
}
return 0;
}