Skip to content

Commit 112e429

Browse files
authored
[20251130] BOJ / G5 / 암호 만들기 / 강신지
1 parent eb9b2f1 commit 112e429

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static int l, c;
7+
static char[] chars;
8+
static char[] selected;
9+
static StringBuilder sb = new StringBuilder();
10+
11+
public static void main(String[] args) throws Exception {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
StringTokenizer st = new StringTokenizer(br.readLine());
14+
15+
l = Integer.parseInt(st.nextToken());
16+
c = Integer.parseInt(st.nextToken());
17+
18+
chars = new char[c];
19+
st = new StringTokenizer(br.readLine());
20+
for (int i = 0; i < c; i++) {
21+
chars[i] = st.nextToken().charAt(0);
22+
}
23+
24+
Arrays.sort(chars);
25+
26+
selected = new char[l];
27+
28+
dfs(0, 0, 0, 0);
29+
30+
System.out.print(sb);
31+
}
32+
33+
static void dfs(int idx, int depth, int vowel, int consonant) {
34+
if (depth == l) {
35+
if (vowel >= 1 && consonant >= 2) {
36+
sb.append(selected).append('\n');
37+
}
38+
return;
39+
}
40+
41+
if (idx == c) {
42+
return;
43+
}
44+
45+
char ch = chars[idx];
46+
selected[depth] = ch;
47+
if (isVowel(ch)) {
48+
dfs(idx + 1, depth + 1, vowel+ 1, consonant);
49+
} else {
50+
dfs(idx + 1, depth + 1, vowel, consonant + 1);
51+
}
52+
53+
dfs(idx + 1, depth, vowel, consonant);
54+
}
55+
56+
static boolean isVowel(char c) {
57+
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
58+
}
59+
}
60+
```

0 commit comments

Comments
 (0)