Skip to content

Commit c24e0ea

Browse files
authored
Merge pull request #469 from AlgorithmWithGod/suyeun84
[20250715] BOJ / G5 / A와 B / 김수연
2 parents 62893bb + 29830b0 commit c24e0ea

File tree

1 file changed

+35
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)