// 判断字符串中,出现次数最多的子串
#include <stdio.h>
#include <string.h>
void getMaxSubString(char* str)
{
if (str==NULL)
{
return;
}
char* pStart = str;
char subString[100];
subString[0] = '\0';
int count = 0;
while ( *pStart!='\0')
{
char *pSub = pStart;
int iStep = 1;
int i=0;
int k = iStep;
int tmp = 1;
while (k < strlen(pSub))
{
int j=0;
tmp = 1;
if (pSub[j] == pSub[k])
{
while ( pSub[j++] == pSub[k++])
{
if (j == iStep)
{
tmp++;
j = 0;
}
}
if (tmp > count)
{
count = tmp;
int m1=0,m2=0;
subString[0] = '\0';
while (m1!=iStep )
subString[m1++]=pSub[m2++];
subString[iStep] = '\0';
}
}else
{
iStep++;
k++;
}
}
pStart++;
}
printf("Longest sub String: %s\nThe time:%d\n",subString,count);
}
void main()
{
char p[] = "abcdabcd";
getMaxSubString(p);
}