-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek3_Day5.java
More file actions
68 lines (62 loc) · 1.49 KB
/
Week3_Day5.java
File metadata and controls
68 lines (62 loc) · 1.49 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
60
61
62
63
64
65
66
67
68
package Algorithm3;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Week3_Day5 {
public static Set<Character> moeum = new HashSet<>();
public static ArrayList<Character> al = new ArrayList<>();
public static char[] alphabet;
public static int L;
public static int C;
public static void main(String[] args) throws IOException {
moeum.add('a');
moeum.add('e');
moeum.add('i');
moeum.add('o');
moeum.add('u');
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String info[] = br.readLine().split(" ");
L = Integer.parseInt(info[0]);
C = Integer.parseInt(info[1]);
alphabet = new char[C];
String[]line = br.readLine().split(" ");
for(int i=0; i<C; i++) {
alphabet[i] = line[i].charAt(0);
}
Arrays.sort(alphabet);
dfs(0);
}
private static boolean isMoeum(char c) {
if(moeum.contains(c)) {
return true;
}
return false;
}
private static void dfs(int step) {
if(al.size() == L) {
int count = 0;
String result = "";
for(char c : al) {
if(isMoeum(c)) {
count++;
}
result += c;
}
// 모음 개수가 1이상이고 나머지(자음) 개수가 2 이상
if(count >= 1 && (L-count) >= 2) {
System.out.println(result);
}
return;
}
for(int i=step; i<C; i++) {
char K = alphabet[i];
al.add(K);
dfs(i+1);
al.remove(al.size()-1);
}
}
}