首页 > 其他 > 详细

【求最大公共子串长度】

时间:2017-04-12 09:52:35      阅读:170      评论:0      收藏:0      [点我收藏+]
#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\n", fun("abcdkkk", "baabcdadabc"));    //4
    return 0;
}

 

【求最大公共子串长度】

原文:http://www.cnblogs.com/libra-yong/p/6683201.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!