-
Notifications
You must be signed in to change notification settings - Fork 1
/
Baekjoon1759.java
109 lines (80 loc) · 2.75 KB
/
Baekjoon1759.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package algo.Algorithms;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
/**
* https://www.acmicpc.net/problem/1759
* 백준 1759 암호구하기
*/
public class Baekjoon1759 {
static List<Character> alphabetList = new ArrayList<>();
static List<Character> nounList = new ArrayList<>();
static List<String> answerList = new ArrayList<>();
static int L, C;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
nounList.add('a');
nounList.add('e');
nounList.add('i');
nounList.add('o');
nounList.add('u');
for (int i = 0; i < 26; i++) {
alphabetList.add(Character.toLowerCase(new Character((char) (65 + i))));
}
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
L = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
char[] inputs = new char[C];
st = new StringTokenizer(br.readLine(), " ");
int i = 0;
while (st.hasMoreTokens()) {
inputs[i++] = st.nextToken().charAt(0);
}
Arrays.sort(inputs);
List<Character> answer = new ArrayList<>();
findAll(inputs, answer, 0);
for(String str : answerList){
if(isPassCondition(str)) System.out.println(str);
}
}
private static boolean isPassCondition(String str) {
int nounCount = 0;
int count = 0;
for(char c : str.toCharArray()){
if(nounList.contains(c)) nounCount++;
else count++;
}
if(nounCount > 0 && count>1) return true;
return false;
}
private static void findAll(char[] inputs, List<Character> answer, int index) {
if(answer.size() == L){
StringBuilder sb = new StringBuilder();
for(char c : answer){
sb.append(c);
}
answerList.add(sb.toString());
return;
}
if(index>=C) return;
List<Character> chooseThis = new ArrayList<>();
chooseThis.addAll(answer);
chooseThis.add(inputs[index]);
findAll(inputs, chooseThis, index+1);
findAll(inputs, answer, index+1);
}
private static boolean checkCondition(List<Character> answer) {
int nounCount = 0;
int consonantCount = 0;
for (char noun : nounList) {
if (answer.contains(noun)) nounCount++;
else consonantCount++;
}
if (nounCount > 0 && consonantCount > 1) return true;
return false;
}
}