void FindCommon(char* s1, char* s2)
{
int length1;
int length2;
int length;
int i;
int j;
int k;
int tmpmax = 0;
int max = 0;
char tmp[10] = {};
char res[10] = {};
length1 = strlen(s1);
length2 = strlen(s2);
length = length1 + length2;
i = length1-1;
j = 0;
while (length > 0)
{
while (i < length1)
{
while (s1[i] == s2[j])
{
tmp[tmpmax] = s1[i];
tmpmax = tmpmax + 1;
i++;
j++;
if (j >= length2)
{
break;
}
}
if (max < tmpmax)
{
max = tmpmax;
strcpy_s(res, tmp);
for (k = 0; k < tmpmax; ++k)
{
tmp[k] = 0;
}
tmpmax = 0;
}
else
{
for (k = 0; k < tmpmax; ++k)
{
tmp[k] = 0;
}
tmpmax = 0;
}
i++;
j++;
if (j >= length2)
{
break;
}
}
length--;
i = length - length2 - 1;
if (i < 0)
{
j = abs(i);
i = 0;
}
else
{
j = 0;
}
}
printf_s("%s", res);
}
找出两个字符串中最大公共子字符串
最新推荐文章于 2021-03-12 02:09:14 发布