-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain2.java
48 lines (39 loc) Β· 1.33 KB
/
Main2.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
package DFS.P1759;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main2 {
static int L, C;
static char[] arr;
static StringBuilder res = new StringBuilder();
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/DFS/P1759/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
L = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
arr = new char[C];
st = new StringTokenizer(br.readLine());
for (int c = 0; c < C; c++) arr[c] = st.nextToken().charAt(0);
Arrays.sort(arr);
comb(0, 0);
}
static void comb(int start, int cnt) {
if (cnt == L) {
res.setLength(L);
int v = 0, c = 0;
for (int i = 0; i < L; i++) {
if ("aeiou".indexOf(res.charAt(i)) >= 0) v ++;
else c ++;
}
if (v >= 1 && c >= 2) System.out.println(res);
return;
}
for (int i = start; i < C; i++) {
res.insert(cnt, arr[i]);
comb(i+1, cnt+1);
}
}
}