ZqrFerrari
努力学习,开心生活

回文,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;
}

 

 

posted on 2010-07-12 23:21  赵情融  阅读(377)  评论(0编辑  收藏  举报