From 79c69c2415ecd66c93840157857a8f1812ffd845 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Thu, 17 Jul 2025 23:36:48 +0900 Subject: [PATCH] =?UTF-8?q?[20250717]=20BOJ=20/=20G5=20/=20A=EC=99=80=20B?= =?UTF-8?q?=202=20/=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202507/17 BOJ G5 A\354\231\200 B 2.md" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "Seol-JY/202507/17 BOJ G5 A\354\231\200 B 2.md" diff --git "a/Seol-JY/202507/17 BOJ G5 A\354\231\200 B 2.md" "b/Seol-JY/202507/17 BOJ G5 A\354\231\200 B 2.md" new file mode 100644 index 00000000..b8a99dd5 --- /dev/null +++ "b/Seol-JY/202507/17 BOJ G5 A\354\231\200 B 2.md" @@ -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; + } +} +```