From bb57292bd7ffeb0490cef330c711dd04b57fc6bf Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Wed, 23 Jul 2025 22:55:59 +0900 Subject: [PATCH] =?UTF-8?q?[20250723]=20BOJ=20/=20G5=20/=20=EC=95=A0?= =?UTF-8?q?=EB=84=88=EA=B7=B8=EB=9E=A8=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\353\204\210\352\267\270\353\236\250.md" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "LiiNi-coder/202507/23 BOJ \354\225\240\353\204\210\352\267\270\353\236\250.md" diff --git "a/LiiNi-coder/202507/23 BOJ \354\225\240\353\204\210\352\267\270\353\236\250.md" "b/LiiNi-coder/202507/23 BOJ \354\225\240\353\204\210\352\267\270\353\236\250.md" new file mode 100644 index 00000000..657a3174 --- /dev/null +++ "b/LiiNi-coder/202507/23 BOJ \354\225\240\353\204\210\352\267\270\353\236\250.md" @@ -0,0 +1,52 @@ +```java +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.Arrays; + +public class Main { + private static BufferedReader br; + private static int[] charCount; // 각 문자 a~z의 개수 + private static char[] inputChars; + private static char[] output; + private static int length; + private static StringBuilder sb; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine()); + sb = new StringBuilder(); + + for (int testCase = 0; testCase < t; testCase++) { + inputChars = br.readLine().toCharArray(); + Arrays.sort(inputChars); + length = inputChars.length; + output = new char[length]; + charCount = new int[26]; + + for (char c : inputChars) { + charCount[c - 'a']++; + } + + permute(0); + } + System.out.print(sb); + } + + private static void permute(int depth) { + if (depth == length) { + sb.append(output).append('\n'); + return; + } + + for (int i = 0; i < 26; i++) { + if (charCount[i] > 0) { + output[depth] = (char) ('a' + i); + charCount[i]--; + permute(depth + 1); + charCount[i]++; + } + } + } +} +```