两遍遍历,数组查找

while True:
    try:
        s1= input()
        s2= input()
        if len(s1)> len(s2):
            s1,s2 = s2,s1
        length=0
        for i in range(len(s1)):
            for j in range(i+1,len(s1)+1):
                if s1[i:j] in s2 and (j-i)>length:
                    length=j-i
                    res = s1[i:j]
        print(res)
    except:
        break