-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.java
More file actions
47 lines (36 loc) · 1.11 KB
/
Program.java
File metadata and controls
47 lines (36 loc) · 1.11 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
package practice.temp;
import java.io.*;
import java.util.*;
public class Program {
public static void main(String[] args) {
numbers = new int[]{1, 2, 3};
isSelected = new boolean[3];
permutation(0);
}
static int[] numbers;
static boolean[] isSelected;
static void permutation(int cnt) {
for (int n = 0; n < cnt; n++) System.out.print("\t");
System.out.printf("permutation(cnt: %d)\n", cnt);
for (int n = 0; n < cnt; n++) System.out.print("\t");
System.out.println(Arrays.toString(numbers));
for (int n = 0; n < cnt; n++) System.out.print("\t");
System.out.println(Arrays.toString(isSelected));
if (cnt == 3) {
// 순열 생성 완료
for (int n = 0; n < cnt; n++) System.out.print("\t");
System.out.print("순열 생성 완료 = ");
System.out.println(Arrays.toString(numbers));
System.out.println();
return;
}
System.out.println();
for (int i = 0; i < 3; i++) {
if (isSelected[i]) continue;
numbers[cnt] = i + 1;
isSelected[i] = true;
permutation(cnt + 1);
isSelected[i] = false;
}
}
}