判断字符串是否为回文字符串

c++:

reverse函数包含在头文件中

用reverse函数反转字符串再判断

int judge(string a)
{
	string b;
	b = a;
	reverse(a.begin(), a.end());
	if (a == b)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

c:

bool judge(char*a, int start, int end)
{
	while (start < end)
	{
		if (a[start] == a[end])
		{
			start++;
			end--;

		}
		else
		{
			return false;
		}
	}
	return true;
}

你可能感兴趣的:(c++,c语言)