Skip to content

Commit 531c310

Browse files
authored
[20250827] BOJ / G5 / A와 B 2 / 이인희
1 parent 03d42ab commit 531c310

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
6+
public class Main {
7+
private static String S, T;
8+
private static boolean isFind = false;
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+
15+
dfs(T);
16+
System.out.println(isFind ? 1 : 0);
17+
}
18+
19+
private static void dfs(String cur) {
20+
if (isFind)
21+
return;
22+
if (cur.length() == S.length()) {
23+
if (cur.equals(S)) isFind = true;
24+
return;
25+
}
26+
27+
// 마지막이 A라면 A 제거
28+
if (cur.charAt(cur.length() - 1) == 'A') {
29+
dfs(cur.substring(0, cur.length() - 1));
30+
}
31+
32+
// 첫 글자가 B라면 B 제거 후 뒤집기
33+
if (cur.charAt(0) == 'B') {
34+
StringBuilder sb = new StringBuilder(cur.substring(1));
35+
dfs(sb.reverse().toString());
36+
}
37+
}
38+
}
39+
40+
```

0 commit comments

Comments
 (0)