File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ static String S , T ;
7+ static int answer = 0 ;
8+
9+ public static void main (String [] args ) throws IOException {
10+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
11+ S = br. readLine();
12+ T = br. readLine();
13+
14+ solve(T );
15+ System . out. println(answer);
16+ }
17+
18+ static void solve (String cur ) {
19+ if (cur. length() == S . length()) {
20+ if (cur. equals(S )) {
21+ answer = 1 ;
22+ }
23+ return ;
24+ }
25+
26+ if (answer == 1 ) return ;
27+
28+ if (cur. charAt(cur. length() - 1 ) == ' A' ) {
29+ solve(cur. substring(0 , cur. length() - 1 ));
30+ }
31+
32+ if (cur. charAt(0 ) == ' B' ) {
33+ String next = cur. substring(1 );
34+ StringBuilder sb = new StringBuilder (next);
35+ solve(sb. reverse(). toString());
36+ }
37+ }
38+ }
39+ ```
You can’t perform that action at this time.
0 commit comments