File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments