-
Notifications
You must be signed in to change notification settings - Fork 2
/
yess.java
50 lines (46 loc) · 1.15 KB
/
yess.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
//문자열뒤에 a추가
//문자열을 뒤집고 뒤에 b추가
static boolean flag = false;
public static void main(String [] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
String t = br.readLine();
int len = t.length() - s.length();
StringBuilder sb = new StringBuilder (t);
while (len >= 0 ) {
if (sb.toString().equals(s)) {
flag = true;
break;
}
if (sb.charAt(sb.length()-1) == 'B') {
sb.setLength(sb.length()-1);
sb.reverse();
}
else {
sb.setLength(sb.length()-1);
}
len --;
}
System.out.println(flag? 1:0);
}
static void dfs(StringBuilder sb, int cnt, int len, String target) {
if (flag) return;
if (cnt == len ) {
if (sb.toString().equals(target)) {
flag =true;
}
return ;
}
sb.append("A");
dfs(sb,cnt+ 1, len,target);
sb.setLength(sb.length() - 1);
sb.reverse().append("B");
dfs(sb,cnt + 1, len,target);
sb.setLength(sb.length() -1);
sb.reverse();
}
}