Skip to content

Commit eb13c19

Browse files
committed
[20250921] BOJ / G5 / 애너그램 / 김민진
1 parent 1f49f0f commit eb13c19

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
```java
2+
import java.io.*;
3+
4+
public class BJ_6443_애너그램 {
5+
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
9+
private static String input;
10+
private static int length;
11+
private static int[] alphabets;
12+
private static char[] result;
13+
14+
public static void main(String[] args) throws IOException {
15+
int T = Integer.parseInt(br.readLine());
16+
17+
while (T-- > 0) {
18+
sol();
19+
}
20+
bw.flush();
21+
bw.close();
22+
br.close();
23+
}
24+
25+
private static void sol() throws IOException {
26+
input = br.readLine();
27+
length = input.length();
28+
alphabets = new int[26];
29+
result = new char[length];
30+
31+
for (int i = 0; i < length; i++) {
32+
alphabets[input.charAt(i) - 'a']++;
33+
}
34+
35+
perm(0);
36+
}
37+
38+
private static void perm(int depth) throws IOException {
39+
if (depth == length) {
40+
bw.write(result);
41+
bw.write('\n');
42+
return;
43+
}
44+
45+
for (int i = 0; i < 26; i++) {
46+
if (alphabets[i] > 0) {
47+
alphabets[i]--;
48+
result[depth] = (char) (i + 'a');
49+
perm(depth + 1);
50+
alphabets[i]++;
51+
}
52+
}
53+
}
54+
}
55+
```

0 commit comments

Comments
 (0)