File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments