-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_1802.java
More file actions
79 lines (62 loc) · 2.16 KB
/
BOJ_1802.java
File metadata and controls
79 lines (62 loc) · 2.16 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.io.*;
import java.util.*;
public class BOJ_1802 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
boolean isEqual;
/*
// 방법 1
for (int i = 0; i < T; i++) {
isEqual = true;
String str = br.readLine();
String[] strArray = str.split("");
int end = strArray.length;
while (end > 2) {
int mid = end / 2; // 중간 인덱스 값 찾기
String[] leftArray = Arrays.copyOfRange(strArray, 0, mid);
String[] rightArray = Arrays.copyOfRange(strArray, mid+1, end);
if (!check(leftArray, rightArray)) {
isEqual = false;
break;
}
end = mid;
}
System.out.println(isEqual? "YES":"NO");
}
*/
for(int i = 0; i < T; i++) {
isEqual = true;
String str = br.readLine();
int len = str.length();
int[] input = new int[len];
for (int j = 0; j < len; j++) {
input[j] = Integer.parseInt(String.valueOf(str.charAt(j)));
}
while (isEqual && len > 1) {
for (int j = 0; j < len / 2; j++) {
if (input[j] + input[len - 1 - j] != 1) {
isEqual = false;
break;
}
}
len /= 2;
}
System.out.println(isEqual ? "YES" : "NO");
}
}
// 비교
private static boolean check(String[] leftArray, String[] rightArray) {
for (int i = 0; i < leftArray.length; i++) {
if (leftArray[i].equals("0")) {
leftArray[i] = "1";
} else {
leftArray[i] = "0";
}
}
List<String> leftList = Arrays.asList(leftArray);
Collections.reverse(leftList);
leftList.toArray(leftArray);
return Arrays.equals(leftArray, rightArray);
}
}