Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions zinnnn37/202602/24 BOJ G5 A와 B 2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
```java
import java.io.*;

public class BJ_12919_A와_B_2 {

private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

private static int res;
private static String from, to;

public static void main(String[] args) throws IOException {
init();
sol();
}

private static void init() throws IOException {
from = br.readLine();
to = br.readLine();
}

private static void sol() throws IOException {
bw.write(rec(to) + "");
bw.flush();
bw.close();
br.close();
}

private static int rec(String to) throws IOException {
if (from.equals(to)) {
return 1;
}

if (to.length() < from.length()) {
return 0;
}

if (to.charAt(to.length() - 1) == 'A') {
res = rec(to.substring(0, to.length() - 1));
}

if (to.charAt(0) == 'B') {
StringBuilder tmp = new StringBuilder(to.substring(1));
res = Math.max(res, rec(tmp.reverse().toString()));
}
return res;
}

}
```