题解 | #公共子串计算#

公共子串计算

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

#include <stdio.h>

int main()
{
    char str1[150] = {0};
    char str2[150] = {0};
    gets(str1);
    gets(str2);
    
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    int max = 0;
    int count = 0;
    for(int i = 0; i < len1; i++)
    {
        for(int j = 0; j < len2; j++)
        {
            int x = i;	//定义字符串坐标
            int y = j;
            while(str1[x] == str2[y] && x < len1 && y < len2)
            {
                x++;
                y++;
                count++;
            }
            if(max < count)
            {
                max = count;
            }
            count = 0;
        }
    }
    
    printf("%d\n", max);
    return 0;
}
全部评论

相关推荐

不对是145个人…嗯…&nbsp;大家都没发现秋招提前批来了嘛..笑死我了
牛客39712426...:投了也是浪费时间,之前投米实习,除了浪费我时间写笔试题没有任何反馈,懒得投了
26届校招投递进展
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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