Skip to content

Commit 198c9df

Browse files
committed
[백준] 공통 부분 문자열 / 골드 5 / 40분
https://www.acmicpc.net/problem/5582
1 parent 5a2067f commit 198c9df

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
string1 = input()
2+
string2 = input()
3+
4+
dp = [[0] * len(string1) for _ in range(len(string2))]
5+
6+
for i in range(len(string2)):
7+
for j in range(len(string1)):
8+
# 두 문자열의 i번째 문자와 j번째 문자가 같을때
9+
if string2[i] == string1[j]:
10+
if i > 0 and j > 0:
11+
dp[i][j] = dp[i-1][j-1] + 1
12+
else:
13+
dp[i][j] = 1
14+
else:
15+
dp[i][j] = 0
16+
17+
# dp테이블에서 최댓값 찾기
18+
print(max(max(row) for row in dp))

0 commit comments

Comments
 (0)