0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
a,b = input(),input() if len(a)>len(b): temp = a a = b b = temp dp = [[0 for _ in range(len(b)+1)] for _ in range(len(a)+1) ] max_dp = 0 x,y = 0,0 for i in range(1,len(a)+1): for j in range(1,len(b)+1): if a[i-1]==b[j-1]: dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1) if dp[i][j]>max_dp: max_dp = dp[i][j] x,y = i-1,j-1
print(a[x-max_dp+1:x+1])
|