이제는 변형 문제도 풀 수 있게 되었다! 신나~!
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
public class Main {
static int L;
static int C;
static int[] arrAnswer;
static String[] arrAbc;
static int cntAeiou;
static int cntElse;
static StringBuilder sb = new StringBuilder();
static String strAeiou = "aeiou";
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
L = Integer.parseInt(input[0]);
C = Integer.parseInt(input[1]);
arrAnswer = new int[L];
arrAbc = br.readLine().split(" ");
Arrays.sort(arrAbc);
recur( 0, 0);
System.out.println(sb);
}
static void recur(int start, int depth){
StringBuilder sbTmp;
if(depth == L){ // L개라면
sbTmp = new StringBuilder();
cntAeiou = 0;
cntElse = 0;
for(int i : arrAnswer){
sbTmp.append(arrAbc[i]);
if(strAeiou.contains(arrAbc[i])){ // 자모음 카운트
cntAeiou++;
}else{
cntElse++;
}
}
if(cntAeiou > 0 && cntElse > 1){
sb.append(sbTmp);
sb.append("\n");
}
return;
}
for(int i=start; i<C; i++){
arrAnswer[depth] = i;
recur(i+1,depth + 1);
}
}
}
'알고리즘 > 백트래킹' 카테고리의 다른 글
[백준 풀이_Java] 73646155 N과 M (3) (실버 3) (0) | 2024.02.19 |
---|---|
[백준 풀이_Java] 15652 N과 M (4) (0) | 2024.02.16 |
[백준 풀이_Java] 1182 부분수열의 합 (실버2) (0) | 2024.02.15 |
[백준 풀이_Java] 73447483 로또 (실버2) (0) | 2024.02.15 |
[백준 풀이_Java] 14888 연산자 끼워넣기 (실버1) (0) | 2024.02.08 |