字符串中连续出现次数最多的子串

求一个字符串中连续出现次数最多的子串

题目: 求一个字符串中连续出现次数最多的子串,例如:abcbcd 最多的子串为bc

#include <iostream>
#include <string.h>
using namespace std;
char substr[255];
void findmaxsubstr(char *str){
			
			int len=strlen(str);
			int count=0;
			int maxcount=0;
			for (int i=0;i<len;i++)
			{
				for(int j=i+1;j<len;j++){
						int n=j-i;
						count=1;
					if (strncmp(&str[i],&str[j],n)==0)
					{
						count++;
						for (int k=j+n;k<len;k+=n)
						{
							if (strncmp(&str[i],&str[k],n))
							{
								count++;
							}
							else
								break;
						}
						if (maxcount<count)
						{
							maxcount=count;
							memcpy(substr,&str[i],n);
						}
					}
				}
			}
	
}