Skip to content

Commit 2062372

Browse files
authored
Merge pull request #488 from AlgorithmWithGod/Seol-JY
[20250717] BOJ / G5 / A와 B 2 / 설진영
2 parents e803c10 + 79c69c2 commit 2062372

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
6+
public class Main {
7+
static int K;
8+
static String S, T;
9+
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
S = br.readLine();
13+
T = br.readLine();
14+
K = T.length();
15+
16+
System.out.println(dfs(S, T));
17+
}
18+
19+
public static int dfs(String s, String t) {
20+
if (s.length() == t.length()) {
21+
return s.equals(t) ? 1 : 0;
22+
}
23+
24+
if (t.charAt(0) == 'B') {
25+
String reversed = new StringBuilder(t.substring(1)).reverse().toString();
26+
if (dfs(s, reversed) == 1) return 1;
27+
}
28+
29+
if (t.charAt(t.length() - 1) == 'A') {
30+
if (dfs(s, t.substring(0, t.length() - 1)) == 1) return 1;
31+
}
32+
33+
return 0;
34+
}
35+
}
36+
```

0 commit comments

Comments
 (0)