题解 | #公共子串计算#
公共子串计算
https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
#include <stdio.h>
#include <string.h>
int main() {
char shor[150];
char lon[150];
int n1 = strlen(shor);
int n2 = strlen(lon);
while(~scanf("%s",shor))
{
scanf("%s",lon);
char tem[150];
if(strlen(shor)>strlen(lon))
{
strcpy(tem,shor);
strcpy(shor, lon);
strcpy(lon,tem);
}
int n1 = strlen(shor);
int n2 = strlen(lon);
int i,j,k;
for(j = n1;j>=0;j--)
{
for(k=0;k<=n1-j;k++)
{
for(i=0;i<=n2-j;i++)
{
if(j==0)
{
printf("0");
return 0;
}
else if(strncmp(&shor[k], &lon[i],j)==0)
{
printf("%d",j);
return 0;
}
}
}
}
}
}
美的集团公司福利 815人发布
查看9道真题和解析