-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathUVa00441_Lotto.java
73 lines (62 loc) · 1.47 KB
/
UVa00441_Lotto.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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 382 (441 - Lotto) */
/* SUBMISSION: 09046538 */
/* SUBMISSION TIME: 2011-07-13 21:11:44 */
/* LANGUAGE: 2 */
import java.util.*;
public class UVa00441_Lotto {
static class Subset implements Comparable<Subset> {
int[] set;
int n;
public Subset(int[] v) {
this.set = v;
this.n = v.length;
}
public int compareTo(Subset s) {
for (int i = 0; i < this.n; ++i)
if (this.set[i] != s.set[i])
return this.set[i] - s.set[i];
return 0;
}
public String toString() {
String res = "";
for (int i = 0; i < this.n; ++i) {
if (i > 0)
res += " ";
res += this.set[i];
}
return res;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
boolean first = true;
while (true) {
int k = in.nextInt();
if (k == 0)
break;
int[] set = new int[k];
List<Subset> subsets = new ArrayList<Subset>();
for (int i = 0; i < k; ++i)
set[i] = in.nextInt();
if (first)
first = false;
else
System.out.println();
for (int i = 0; i < (1 << k); ++i) {
if (Integer.bitCount(i) == 6) {
int[] sub = new int[6];
int ind = 0;
for (int j = 0; j < k; ++j)
if ((i & (1 << j)) != 0)
sub[ind++] = set[j];
subsets.add(new Subset(sub));
}
}
Collections.sort(subsets);
for (Subset s : subsets)
System.out.println(s);
}
}
}