input input lx len ly len ly for in range lx for in range lx for in ra

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
x = input()
y = input()
lx = len(x)
ly = len(y)
A = [[0] * (ly + 1) for i in range(lx + 1)]
for i in range(1, lx + 1):
for j in range(1, ly + 1):
if x[i - 1] == y[j - 1]:
A[i][j] = A[i - 1][j - 1] + 1
else:
A[i][j] = max(A[i - 1][j], A[i][j - 1])
for i in range(1, lx + 1):
for j in range(1, ly + 1):
print('%2d' %A[i][j], end = '')
print('\n', end = '')
ans = ''
i = lx
j = ly
while i > 0 and j >= 0:
if x[i - 1] == y[j - 1]:
ans = x[i - 1] + ans
i -= 1
j -= 1
elif A[i - 1][j] >= A[i][j - 1]:
i -= 1
else:
j -= 1
print(ans)