백준 1759 암호만들기
import java.util.*;
import java.io.*;
public class Main {
static int L;
static int C;
static ArrayList <String> alphabet;
static boolean [] visited;
static void make(int count, int index) {
if(count == L) {
int aeiou = 0;
int other = 0;
StringBuilder sb = new StringBuilder();
for(int i = 0; i < C; i++) {
if(visited[i]) {
sb.append(alphabet.get(i));
if(alphabet.get(i).equals("a") || alphabet.get(i).equals("e") || alphabet.get(i).equals("i") ||
alphabet.get(i).equals("o") || alphabet.get(i).equals("u")) {
aeiou ++;
}
else {
other++;
}
}
}
if(aeiou > 0 && other >= 2)
System.out.println(sb);
}
for(int i = index; i < C; i++) {
visited[i] = true;
make(count+1, i+1);
visited[i] = false;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
L = sc.nextInt();
C = sc.nextInt();
visited = new boolean [C];
alphabet = new ArrayList<String>();
for(int i = 0; i < C; i++) {
alphabet.add(sc.next());
}
alphabet.sort(null);
make(0,0);
}
}