现在的位置: 首页 > 综合 > 正文

编程挑战(2)

2019年01月11日 ⁄ 综合 ⁄ 共 549字 ⁄ 字号 评论关闭

回文是一种字符对称的字符串,无论从前面往后读还是从后往前读结果都一样。

// 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;
}

 

【上篇】
【下篇】

抱歉!评论已关闭.