def find_lcsubstr(s1, s2):
# dp矩阵
m = [[0]*len(s2) for j in range(len(s1))]
# 记录最大的公共子串长度
nmax = 0
# 记录最大的公共子串长度的结尾索引
p = 0
for i in range(len(s1)-1):
for j in range(len(s2)-1):
if s1[i] == s2[j]:
m[i+1][j+1] = m[i][j] + 1
if m[i+1][j+1] > nmax:
nmax = m[i+1][j+1]
p = i+1
return s1[p-nmax:p], nmax
print(find_lcsubstr('s1abcddabc', 'ddabca'))