题解 | #公共子串计算#
公共子串计算
http://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
#include <stdio.h>
int main()
{
char str1[150] = {0};
char str2[150] = {0};
gets(str1);
gets(str2);
int len1 = strlen(str1);
int len2 = strlen(str2);
int max = 0;
int count = 0;
for(int i = 0; i < len1; i++)
{
for(int j = 0; j < len2; j++)
{
int x = i; //定义字符串坐标
int y = j;
while(str1[x] == str2[y] && x < len1 && y < len2)
{
x++;
y++;
count++;
}
if(max < count)
{
max = count;
}
count = 0;
}
}
printf("%d\n", max);
return 0;
}