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
36 changes: 36 additions & 0 deletions Seol-JY/202507/17 BOJ G5 A와 B 2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
static int K;
static String S, T;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
S = br.readLine();
T = br.readLine();
K = T.length();

System.out.println(dfs(S, T));
}

public static int dfs(String s, String t) {
if (s.length() == t.length()) {
return s.equals(t) ? 1 : 0;
}

if (t.charAt(0) == 'B') {
String reversed = new StringBuilder(t.substring(1)).reverse().toString();
if (dfs(s, reversed) == 1) return 1;
}

if (t.charAt(t.length() - 1) == 'A') {
if (dfs(s, t.substring(0, t.length() - 1)) == 1) return 1;
}

return 0;
}
}
```