回文,12321。
这是一个字符串,字符串的第一个和最后一个相同,第二个和倒数第二个相同,用递归这样来实现回文判断。
代码
#include <iostream>
using namespace std;
bool isPalindrome(char str[], size_t n)
{
if (n<=1)
{
return true;
}
else if (str[0]==str[n-1])
{
return isPalindrome(str+1,n-2);
}
else
return false;
}
int main()
{
char str[20];
cin>>str;
cout<<(isPalindrome(str,strlen(str))?"Yes":"No")<<endl;
}
using namespace std;
bool isPalindrome(char str[], size_t n)
{
if (n<=1)
{
return true;
}
else if (str[0]==str[n-1])
{
return isPalindrome(str+1,n-2);
}
else
return false;
}
int main()
{
char str[20];
cin>>str;
cout<<(isPalindrome(str,strlen(str))?"Yes":"No")<<endl;
}