现在的位置: 首页 > 综合 > 正文

用递归实现查找字符串中相同字符连续出现次数的最大值

2013年09月01日 ⁄ 综合 ⁄ 共 331字 ⁄ 字号 评论关闭
#include <iostream>
#include <string.h>
using namespace std;

int CountLongest(char*);

int main()
{
	char szGame[] = "wwklllmmmm";
	cout<<CountLongest(szGame)<<endl;

	return 0;
}

int CountLongest(char* pBuf)
{
	int result = 0;
	char *p = pBuf;

	if(*p=='\0')
		return result;
	while((*p)!='\0'&&(*p)==(*pBuf))
	{
		result++;
		p++;
	}

	return result>CountLongest(p)?result:CountLongest(p);
}

抱歉!评论已关闭.