File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-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+ static int K ;
8+ static String S , T ;
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+ K = T . length();
15+
16+ System . out. println(dfs(S , T ));
17+ }
18+
19+ public static int dfs (String s , String t ) {
20+ if (s. length() == t. length()) {
21+ return s. equals(t) ? 1 : 0 ;
22+ }
23+
24+ if (t. charAt(0 ) == ' B' ) {
25+ String reversed = new StringBuilder (t. substring(1 )). reverse(). toString();
26+ if (dfs(s, reversed) == 1 ) return 1 ;
27+ }
28+
29+ if (t. charAt(t. length() - 1 ) == ' A' ) {
30+ if (dfs(s, t. substring(0 , t. length() - 1 )) == 1 ) return 1 ;
31+ }
32+
33+ return 0 ;
34+ }
35+ }
36+ ```
You can’t perform that action at this time.
0 commit comments