首页 > 试题广场 >

最长公共连续子串

[编程题]最长公共连续子串
  • 热度指数:6604 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
牛牛有两个字符串(可能包含空格),牛牛想找出其中最长的公共连续子串,希望你能帮助他,并输出其长度。

输入描述:
输入为两行字符串(可能包含空格),长度均小于等于50.


输出描述:
输出为一个整数,表示最长公共连续子串的长度。
示例1

输入

abcde
abgde

输出

2
a=raw_input()
b=raw_input()
ct=[]
s=0
fl=0
iflen(a)==1and len(b)!=1:
    fl=1
    fori in b:
        ifa==i:
            print 1
        else:
            print 0
iflen(b)==1:
    fl=1
    fori in a:
        ifb==i:
            print 1
        else:
            print 0   
 
fori in range(len(a)-1):   
    forj in range(len(b)-1):       
        ifa[i]==b[j] and a[i+1]==b[j+1]:
            s=s+1
            break
        elif a[i]==b[j]:
            ct.append(s)
            s=0
ct.append(s)
ifmax(ct)!=0:
     
    print max(ct)+1
else:
    iffl==0:
        print 0

编辑于 2017-03-25 13:24:47 回复(0)

热门推荐

通过挑战的用户