// HuiWenChuan.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
/*
递归判断是否是回文串
回文串:"abccba", "aba"
*/
bool isHuiWenChuan(const string &strTest)
{
static int i = 0;
int j = strlen(strTest.c_str())-1-i;
if (strTest[i] == strTest[j])
{
if (j-i <= 2)
{
return true;
}
else
{
i++;
return isHuiWenChuan(strTest);
}
}
else
{
return false;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
string strVal = "abccba";
string strVal2 = "abcbba";
string strVal3 = "tlt";
bool bH = isHuiWenChuan(strVal);
bool bH2 = isHuiWenChuan(strVal2);
bool bH3 = isHuiWenChuan(strVal3);
return 0;
}
判断回文串的递归函数实现(c++)
最新推荐文章于 2022-03-29 17:55:08 发布