-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path241205-6603.java
54 lines (49 loc) · 1.44 KB
/
241205-6603.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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static StringBuilder sb;
static int k;
static int[] arr;
static int[] result;
static boolean[] visited;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
sb = new StringBuilder();
while (true) {
StringTokenizer st = new StringTokenizer(br.readLine());
k = Integer.parseInt(st.nextToken());
if (k == 0) {
break;
}
arr = new int[k];
for (int i = 0; i < k; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
result = new int[6];
visited = new boolean[k];
solve(0, 0);
sb.append("\n");
}
System.out.print(sb);
}
static void solve(int idx, int depth) {
if (depth == 6) {
for (int i = 0; i < 6; i++) {
sb.append(result[i]).append(" ");
}
sb.append("\n");
return;
}
for (int i = idx; i < k; i++) {
if (visited[i]) {
continue;
}
visited[i] = true;
result[depth] = arr[i];
solve(i + 1, depth + 1);
visited[i] = false;
}
}
}