import sys
s = input().strip() # s当短串,长了就把他和t掉个个
t = input().strip()
# 步骤1:把短串和长串分开,减少遍历次数
if len(s) > len(t):
s, t = t, s
max_length = 0
result = ""
# 步骤2:从最长可能的子串长度开始往下遍历
for i in range(len(s)):
# 子串的结束位置,从i开始,到末尾结束
for j in range(i + 1, len(s) + 1):
substr = s[i:j]
# 步骤3:如果这个子串在t中,并且长度比当前记录的长,就更新
if substr in t and len(substr) > max_length:
max_length = len(substr)
result = substr
print(result)

京公网安备 11010502036488号