-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest222.java
More file actions
59 lines (53 loc) · 1.83 KB
/
test222.java
File metadata and controls
59 lines (53 loc) · 1.83 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
49
50
51
52
53
54
55
56
57
58
59
import java.util.HashSet;
import java.util.Iterator;
public class test222 {
HashSet<Integer> numbersSet = new HashSet<>();
// public boolean isPrime(int num) {
// // 1. 0과 1은 소수가 아니다
// if (num == 0 || num == 1)
// return false;
//
// // 2. 에라토스테네스의 체의 limit 숫자를 계산한다.
// int lim = (int)Math.sqrt(num);
//
// // 3. 에라토스테네스의 체에 따라 lim까지 배수 여부를 확인한다.
// for (int i = 2; i <= lim; i++)
// if (num % i == 0)
// return false;
//
// return true;
// }
public void recursive(String comb, String others) {
// 1. 현재 조합을 set에 추가한다.
if (!comb.equals(""))
numbersSet.add(Integer.valueOf(comb));
// 2. 남은 숫자 중 한 개를 더해 새로운 조합을 만든다.
for (int i = 0; i < others.length(); i++){
String a = others.substring(0, i);
String b = others.substring(i + 1);
recursive(comb + others.charAt(i), others.substring(0, i) + others.substring(i + 1));
}
}
public int solution(String numbers) {
// 1. 모든 조합의 숫자를 만든다.
recursive("", numbers);
System.out.println(numbersSet);
int answer = 0;
return answer;
// 2. 소수의 개수만 센다.
// int count = 0;
// Iterator<Integer> it = numbersSet.iterator();
// while (it.hasNext()) {
// int number = it.next();
// if (isPrime(number))
// count++;
// }
//
// // 3. 소수의 개수를 반환한다.
// return count;
}
public static void main(String[] args) {
test222 sol = new test222();
System.out.println(sol.solution("117"));
}
}