参考代码:
import java.util.Arrays; import java.util.Scanner; public class Main{ static String st; static char[] cha; static char ch[] ; static boolean[] bo; static int count = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); st = sc.next(); ch = st.toCharArray(); bo = new boolean[ch.length]; cha = new char[ch.length]; Arrays.sort(ch); dfs(0); } private static void dfs(int k) { if (k == ch.length){ String s = new String(cha); // 字符数组转字符串 if (st.equals(s)){ System.out.println(count); } count++; } for (int i = 0; i < ch.length; i++) { if (bo[i]){ continue; } bo[i] = true; cha[k] = ch[i]; dfs(k+1); bo[i] = false; } } }
0.0分
1 人评分