Skip to content

Commit 582f688

Browse files
authored
Merge pull request #1100 from AlgorithmWithGod/zinnnn37
[20251012] BOJ / G5 / 암호 만들기 / 김민진
2 parents c0846b9 + 84146bc commit 582f688

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
```java
2+
import java.io.*;
3+
import java.util.Arrays;
4+
import java.util.StringTokenizer;
5+
6+
public class BJ_1759_암호_만들기 {
7+
8+
private static final String VOWELS = "aeiou";
9+
10+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
12+
private static final StringBuilder sb = new StringBuilder();
13+
private static StringTokenizer st;
14+
15+
private static int L, C;
16+
private static String[] chars;
17+
private static int[] candidate;
18+
19+
public static void main(String[] args) throws IOException {
20+
init();
21+
sol(0, 0, 0, 0);
22+
23+
bw.write(sb.toString());
24+
bw.flush();
25+
bw.close();
26+
br.close();
27+
}
28+
29+
private static void init() throws IOException {
30+
st = new StringTokenizer(br.readLine());
31+
L = Integer.parseInt(st.nextToken());
32+
C = Integer.parseInt(st.nextToken());
33+
34+
chars = new String[C];
35+
candidate = new int[L];
36+
st = new StringTokenizer(br.readLine());
37+
for (int i = 0; i < C; i++) {
38+
chars[i] = st.nextToken();
39+
}
40+
Arrays.sort(chars);
41+
}
42+
43+
private static void sol(int depth, int start, int vowels, int consonants) {
44+
if (depth == L) {
45+
if (vowels >= 1 && consonants >= 2) {
46+
appendAns();
47+
}
48+
return;
49+
}
50+
51+
for (int i = start; i < C; i++) {
52+
candidate[depth] = i;
53+
54+
boolean isVowel = VOWELS.contains(chars[i]);
55+
56+
sol(depth + 1, i + 1, isVowel ? vowels + 1 : vowels, isVowel ? consonants : consonants + 1);
57+
}
58+
}
59+
60+
private static void appendAns() {
61+
for (int c : candidate) {
62+
sb.append(chars[c]);
63+
}
64+
sb.append("\n");
65+
}
66+
67+
}
68+
```

0 commit comments

Comments
 (0)