-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path타노스.java
More file actions
48 lines (38 loc) · 1.15 KB
/
타노스.java
File metadata and controls
48 lines (38 loc) · 1.15 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char[] n = br.readLine().toCharArray();
int count_0 = 0, count_1 = 0;
for (char c : n) {
if (c == '0') {
count_0++;
} else {
count_1++;
}
}
count_0 /= 2;
count_1 /= 2;
StringBuilder sb = new StringBuilder();
for (char c : n) {
if (c == '1' && count_1 > 0) {
count_1--;
} else {
sb.append(c);
}
}
StringBuilder res = new StringBuilder();
for (int i = sb.length() - 1; i >= 0; i--) {
char c = sb.charAt(i);
if (c == '0' && count_0 > 0) {
count_0--;
} else {
res.append(c);
}
}
System.out.println(res.reverse());
}
}