题解 | #公共子串计算#
公共子串计算
http://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
#include "stdio.h"
#include "string.h"
int main()
{
char buf1[150],buf2[150];
scanf("%s",buf1);
scanf("%s",buf2);
int len1=strlen(buf1),len2=strlen(buf2),max=0,count=0;
for(int i =0;i<len1;i++)
{
for(int j=0;j<len2;j++)
{
if(buf1[i]==buf2[j])
{
while(1)
{
if(buf1[i+(count)]!=buf2[j+(count)]|| i+(count)>=len1 || j+(count)>=len2)break;
else count+=1;
}
if(count > max) max=count;
count=0;
}
}
}
printf("%d",max);
return 0;
}