#include <stdio.h> #include <string.h> #define N 256 int fun(const char* s1, const char* s2) { int a[N][N]; int len1 = strlen(s1); //字符串s1的长度 int len2 = strlen(s2); //字符串s2的长度 int i,j; memset(a,0,sizeof(int)*N*N); //初始化数组为0 int max = 0; for(i=1; i<=len1; i++){ for(j=1; j<=len2; j++){ if(s1[i-1]==s2[j-1]) { a[i][j] = a[i-1][j-1] + 1; if(a[i][j] > max) { max = a[i][j]; } } } } return max; } int main() { printf("%d ", fun("abcdkkk", "baabcdadabc")); //4 return 0; }