Skip to content

Commit cfcc9a6

Browse files
committed
issue #44 9251
1 parent f8bbad4 commit cfcc9a6

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/backjoon/_9251.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package backjoon;
2+
// https://www.acmicpc.net/problem/9251
3+
4+
import java.io.BufferedReader;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
8+
public class _9251 {
9+
public static void main(String[] args) throws IOException {
10+
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
char[] str1 = br.readLine().toCharArray();
13+
char[] str2 = br.readLine().toCharArray();
14+
15+
int length_1 = str1.length;
16+
int length_2 = str2.length;
17+
18+
int[][] dp = new int[length_1 + 1][length_2 + 1];
19+
20+
for(int i = 1; i <= length_1; i++) {
21+
for(int j = 1; j <= length_2; j++) {
22+
23+
// (i-1)과 (j-1) 번째 문자가 서로 같은 경우
24+
if(str1[i - 1] == str2[j - 1]) {
25+
dp[i][j] = dp[i - 1][j - 1] + 1;
26+
}
27+
28+
// (i-1)과 (j-1) 번째 문자가 서로 다른 경우
29+
else {
30+
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
31+
}
32+
}
33+
}
34+
System.out.println(dp[length_1][length_2]);
35+
}
36+
}
37+
/*
38+
input
39+
ACAYKP
40+
CAPCAK
41+
42+
output
43+
4
44+
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy