Skip to content

Commit 7fc1469

Browse files
committed
[20260224] BOJ / G5 / A와 B 2 / 김민진
1 parent d9c9822 commit 7fc1469

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
```java
2+
import java.io.*;
3+
4+
public class BJ_12919_A와_B_2 {
5+
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
9+
private static int res;
10+
private static String from, to;
11+
12+
public static void main(String[] args) throws IOException {
13+
init();
14+
sol();
15+
}
16+
17+
private static void init() throws IOException {
18+
from = br.readLine();
19+
to = br.readLine();
20+
}
21+
22+
private static void sol() throws IOException {
23+
bw.write(rec(to) + "");
24+
bw.flush();
25+
bw.close();
26+
br.close();
27+
}
28+
29+
private static int rec(String to) throws IOException {
30+
if (from.equals(to)) {
31+
return 1;
32+
}
33+
34+
if (to.length() < from.length()) {
35+
return 0;
36+
}
37+
38+
if (to.charAt(to.length() - 1) == 'A') {
39+
res = rec(to.substring(0, to.length() - 1));
40+
}
41+
42+
if (to.charAt(0) == 'B') {
43+
StringBuilder tmp = new StringBuilder(to.substring(1));
44+
res = Math.max(res, rec(tmp.reverse().toString()));
45+
}
46+
return res;
47+
}
48+
49+
}
50+
```

0 commit comments

Comments
 (0)