Skip to content

Commit 22ac3f0

Browse files
authored
Merge pull request #1511 from AlgorithmWithGod/JHLEE325
[20251125] BOJ / G5 / 공통 부분 문자열 / 이준희
2 parents 8df0bcb + d3cf55e commit 22ac3f0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
9+
String S1 = br.readLine();
10+
String S2 = br.readLine();
11+
12+
int n = S1.length();
13+
int m = S2.length();
14+
15+
int[][] dp = new int[n + 1][m + 1];
16+
int answer = 0;
17+
18+
for (int i = 1; i <= n; i++) {
19+
for (int j = 1; j <= m; j++) {
20+
if (S1.charAt(i - 1) == S2.charAt(j - 1)) {
21+
dp[i][j] = dp[i - 1][j - 1] + 1;
22+
answer = Math.max(answer, dp[i][j]);
23+
} else {
24+
dp[i][j] = 0;
25+
}
26+
}
27+
}
28+
29+
System.out.println(answer);
30+
}
31+
}
32+
```

0 commit comments

Comments
 (0)