判断回文串的递归函数实现(c++)

来源:互联网 发布:全国各乡镇人口数据 编辑:程序博客网 时间:2024/05/22 16:49
// 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;}