[BOJ 9249] 최장 공통 부분 문자열

View as PDF

Submit solution

Points: 4
Time limit: 1.0s
Memory limit: 256M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

문자열 (T=t_1t_2\dots t_m)가 문자열 (S=s_1s_2\dots s_n)의 부분 문자열이 되려면, (s_{i+1}s_{i+2}\dots s_{i+m} = T)를 만족하는 (0 \le i \le n-m)가 있어야 한다.</p>

두 문자열 (A)와 (B)가 주어졌을 때, 두 문자열의 공통 부분 문자열의 최대 길이와 그 부분 문자열을 구하는 프로그램을 작성하시오.

입력 형식

두 문자열 (A)와 (B)가 한 줄에 하나씩 주어진다. 두 문자열 길이의 합은 20만을 넘지 않는다. 주어지는 문자열은 알파벳 소문자로만 이루어져 있다.

출력 형식

첫째 줄에 두 문자열의 최장 공통 부분 문자열의 길이를 출력한다.</p>

둘째 줄에 해당 부분 문자열을 출력한다.

답이 여러 가지인 경우에는 아무거나 출력한다.

예제 입력

yeshowmuchiloveyoumydearmotherreallyicannotbelieveit
yeaphowmuchiloveyoumydearmother

예제 출력

27
howmuchiloveyoumydearmother

Comments

There are no comments at the moment.