|
| 1 | +```java |
| 2 | +import java.io.BufferedReader; |
| 3 | +import java.io.BufferedWriter; |
| 4 | +import java.io.IOException; |
| 5 | +import java.io.InputStreamReader; |
| 6 | +import java.util.Arrays; |
| 7 | +import java.util.HashSet; |
| 8 | +import java.util.List; |
| 9 | +import java.util.Set; |
| 10 | +import java.util.StringTokenizer; |
| 11 | + |
| 12 | +//TIP 코드를 <b>실행</b>하려면 <shortcut actionId="Run"/>을(를) 누르거나 |
| 13 | +// 에디터 여백에 있는 <icon src="AllIcons.Actions.Execute"/> 아이콘을 클릭하세요. |
| 14 | +public class Main { |
| 15 | + private static BufferedReader br; |
| 16 | + private static int L; |
| 17 | + private static int C; |
| 18 | + private static char[] Arr; |
| 19 | + private static char[] Combination; |
| 20 | + private static StringBuilder answer; |
| 21 | + private static HashSet<Character> mos = new HashSet<>(Set.of('a', 'e', 'i', 'o', 'u')); |
| 22 | + public static void main(String[] args) throws IOException { |
| 23 | + br = new BufferedReader(new InputStreamReader(System.in)); |
| 24 | + String[] temp = br.readLine().split(" "); |
| 25 | + L = Integer.parseInt(temp[0]); |
| 26 | + C = Integer.parseInt(temp[1]); |
| 27 | + Arr = new char[C]; |
| 28 | + Combination = new char[L]; |
| 29 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 30 | + for(int i = 0; i < C; i++) { |
| 31 | + Arr[i] = st.nextToken().charAt(0); |
| 32 | + } |
| 33 | + Arrays.sort(Arr); |
| 34 | + answer = new StringBuilder(); |
| 35 | + dfs(0, 0); |
| 36 | + System.out.println(answer.toString()); |
| 37 | + br.close(); |
| 38 | + } |
| 39 | + |
| 40 | + private static void dfs(int startIndex, int depth) { |
| 41 | + if(depth == L){ |
| 42 | + if(isFullfill()){ |
| 43 | + answer.append(new String(Combination)).append("\n"); |
| 44 | + } |
| 45 | + return; |
| 46 | + } |
| 47 | + for(int i = startIndex; i < C; i++){ |
| 48 | + Combination[depth] = Arr[i]; |
| 49 | + dfs(i + 1, depth + 1); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + private static boolean isFullfill() { |
| 54 | + int countJa = 0; |
| 55 | + int countMo = 0; |
| 56 | + for(char c : Combination){ |
| 57 | + if(mos.contains(c)){ |
| 58 | + countMo++; |
| 59 | + }else{ |
| 60 | + countJa++; |
| 61 | + } |
| 62 | + } |
| 63 | + if(countJa < 2 || countMo < 1){ |
| 64 | + return false; |
| 65 | + } |
| 66 | + return true; |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
0 commit comments