#include <stdio.h>
#include <string.h>
#define N 256
int f(const char* s1, const char* s2)
{
    int a[N][N];
    int len1 = strlen(s1);
    int len2 = strlen(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\n", f("abcdkkk", "baabcdadabc"));
    return 0;
}

 

posted on 2018-03-31 09:11  cindy_1996  阅读(136)  评论(0编辑  收藏  举报