File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+
4+ public class BJ_12919_A 와_B_2 {
5+
6+ private static final BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ private static final BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
8+
9+ private static int res;
10+ private static String from, to;
11+
12+ public static void main (String [] args ) throws IOException {
13+ init();
14+ sol();
15+ }
16+
17+ private static void init () throws IOException {
18+ from = br. readLine();
19+ to = br. readLine();
20+ }
21+
22+ private static void sol () throws IOException {
23+ bw. write(rec(to) + " " );
24+ bw. flush();
25+ bw. close();
26+ br. close();
27+ }
28+
29+ private static int rec (String to ) throws IOException {
30+ if (from. equals(to)) {
31+ return 1 ;
32+ }
33+
34+ if (to. length() < from. length()) {
35+ return 0 ;
36+ }
37+
38+ if (to. charAt(to. length() - 1 ) == ' A' ) {
39+ res = rec(to. substring(0 , to. length() - 1 ));
40+ }
41+
42+ if (to. charAt(0 ) == ' B' ) {
43+ StringBuilder tmp = new StringBuilder (to. substring(1 ));
44+ res = Math . max(res, rec(tmp. reverse(). toString()));
45+ }
46+ return res;
47+ }
48+
49+ }
50+ ```
You can’t perform that action at this time.
0 commit comments