본문 바로가기
  • KEEP HUSTLE!
파이썬 코테 준비

[백준 9252] LCS 2 - Python(파이썬)

by 하수군 2021. 4. 3.
import sys


def solution():
    answer = ''
    for i in range(len(str1)):
        temp = ''
        for j in range(len(str2)):
            if len(temp) < len(check[j]):
                temp = check[j]
            elif str1[i] == str2[j]:
                check[j] = temp + str1[i]

    for ck in check:
        if len(answer) < len(ck):
            answer = ck

    if len(answer):
        print(len(answer), answer, sep='\n')
    else:
        print(0)


str1 = sys.stdin.readline().strip()
str2 = sys.stdin.readline().strip()
check = [''] * len(str2)
solution()

댓글