-
Notifications
You must be signed in to change notification settings - Fork 0
/
J02024_DayConCoTongLe.java
75 lines (67 loc) · 1.7 KB
/
J02024_DayConCoTongLe.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
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
import java.util.*;
import java.io.*;
import java.math.*;
public class J02024_DayConCoTongLe {
public static int n;
public static int ok = 1;
public static int[] a = new int[100];
public static int[] b = new int[100];
public static void st() {
for (int i = 0; i <= n; i++) {
a[i] = 0;
}
}
public static void generate() {
int i = n;
while (i > 0 && a[i] == 1) {
a[i--] = 0;
}
if (i == 0) {
ok = 0;
} else {
a[i] = 1;
}
}
public static void print() {
for (int i = 1; i <= n; i++) {
if (a[i] == 1) {
System.out.print(b[i] + " ");
}
}
System.out.println("");
}
public static boolean check() {
int s = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == 1) {
s += b[i];
}
}
return s % 2 != 0;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
ok = 1;
n = sc.nextInt();
st();
for (int i = 1; i <= n; i++) {
b[i] = sc.nextInt();
}
Arrays.sort(b, 1, n + 1);
int l = 1, r = n;
while (l < r) {
int tmp = b[r];
b[r--] = b[l];
b[l++] = tmp;
}
while (ok > 0) {
if (check()) {
print();
}
generate();
}
}
}
}