Skip to content

Commit b4c2ef2

Browse files
authored
Merge pull request #1973 from AlgorithmWithGod/JHLEE325
[20260226] BOJ / G5 / A와 B 2 / 이준희
2 parents abe86a4 + 4ad7343 commit b4c2ef2

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)