From f42cbb6c7454b0f036008d7189d24df7081d6f23 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sun, 30 Nov 2025 23:44:31 +0900 Subject: [PATCH] =?UTF-8?q?[20251130]=20BOJ=20/=20G5=20/=20=EC=95=94?= =?UTF-8?q?=ED=98=B8=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20/=20=EC=84=A4?= =?UTF-8?q?=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\247\214\353\223\244\352\270\260.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "Seol-JY/202511/30 BOJ G5 \354\225\224\355\230\270 \353\247\214\353\223\244\352\270\260.md" diff --git "a/Seol-JY/202511/30 BOJ G5 \354\225\224\355\230\270 \353\247\214\353\223\244\352\270\260.md" "b/Seol-JY/202511/30 BOJ G5 \354\225\224\355\230\270 \353\247\214\353\223\244\352\270\260.md" new file mode 100644 index 00000000..1bf09f2f --- /dev/null +++ "b/Seol-JY/202511/30 BOJ G5 \354\225\224\355\230\270 \353\247\214\353\223\244\352\270\260.md" @@ -0,0 +1,60 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int L, C; + static char[] chars; + static StringBuilder sb = new StringBuilder(); + static Set vowels = Set.of('a', 'e', 'i', 'o', 'u'); + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + L = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + + chars = new char[C]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < C; i++) { + chars[i] = st.nextToken().charAt(0); + } + + Arrays.sort(chars); // 정렬해두면 자연스럽게 사전순으로 탐색 + + backtrack(0, new char[L], 0); + + System.out.print(sb); + } + + static void backtrack(int start, char[] password, int depth) { + if (depth == L) { + if (isValid(password)) { + sb.append(password).append('\n'); + } + return; + } + + for (int i = start; i < C; i++) { + password[depth] = chars[i]; + backtrack(i + 1, password, depth + 1); + } + } + + static boolean isValid(char[] password) { + int vowelCount = 0; + int consonantCount = 0; + + for (char c : password) { + if (vowels.contains(c)) { + vowelCount++; + } else { + consonantCount++; + } + } + + return vowelCount >= 1 && consonantCount >= 2; + } +} +```