递归判断字符串是否回文

版权声明:晓程原创 https://blog.csdn.net/qq_43469554/article/details/88924799
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
//核心代码
bool is_huiwen(char* str, int size)
{
	if (size <= 1)
		return true;
	if (str[0] != str[size - 1])
		return false;
	return is_huiwen(++str, size - 2);
}
int main()
{
	string s;
	cin >> s;
	char c[20];
	strcpy(c, s.c_str());
	if (is_huiwen(c, s.size()))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43469554/article/details/88924799