Skip to content

Commit df4cc04

Browse files
authored
[20251218] BOJ / G5 / A와 B / 강신지
1 parent e9c5121 commit df4cc04

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

ksinji/202512/18 BOJ A와 B.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
```java
2+
import java.io.*;
3+
4+
public class Main {
5+
public static void main(String[] args) throws Exception {
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
8+
String s = br.readLine();
9+
String t = br.readLine();
10+
11+
char[] a = t.toCharArray();
12+
int l = 0;
13+
int r = a.length - 1;
14+
boolean dir = false;
15+
16+
while (r - l + 1 > s.length()) {
17+
char last = dir ? a[l] : a[r];
18+
if (last == 'A') {
19+
if (dir) l++;
20+
else r--;
21+
} else {
22+
if (dir) l++;
23+
else r--;
24+
dir = !dir;
25+
}
26+
}
27+
28+
for (int i = 0; i < s.length(); i++) {
29+
char c = dir ? a[r - i] : a[l + i];
30+
if (c != s.charAt(i)) {
31+
System.out.print(0);
32+
return;
33+
}
34+
}
35+
36+
System.out.print(1);
37+
}
38+
}
39+
```

0 commit comments

Comments
 (0)