题解 | #公共子串计算#

公共子串计算

https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b

#include <stdio.h>
#include <string.h>

int main() {
    char a[150] = {0};
    char b[150] = {0};
    scanf("%s\n", a);
    scanf("%s\n", b);

    int lena = strlen(a);
    int lenb = strlen(b);
    int n, max = 0;
    for (int i = 0; i < lena; i++) {
        n = 0;
        for (int j = 0; j < lenb; j++) {
            n = 0;
            int x = i, y = j;
            while (a[x] == b[y] && x<lena && y<lenb) {
                n++;
                x++;
                y++;
            }
            max = (max > n) ? max : n;
            n = 0;
        }
    }


    printf("%d\n", max);

    return 0;
}

全部评论

相关推荐

DBsan:我也遇到过好的HR,全程友好交流。这年头基本的礼貌和尊重为什么好多HR都做不到
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务