public class Test_3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { String str = input.nextLine(); char[] chars = str.toCharArray(); ArrayList<String> list = new ArrayList<>(); if (chars.length != 0 && chars != null) { getNumber(chars, list, 0); int resutl = new HashSet<String>(list).size(); System.out.println(resutl); } } } public static void getNumber(char[] chars, ArrayList<String> list, int n) { if (n == chars.length - 1) { String str = new String(chars); if (!list.contains(str)) { list.add(str); } } else { for (int j = n; j < chars.length; ++j) { swap(chars, n, j); getNumber(chars, list, n + 1); swap(chars, n, j); } } } public static void swap(char[] c, int i, int j) { char tmp = c[i]; c[i] = c[j]; c[j] = tmp; } }
字符串排列组合
最新推荐文章于 2022-07-24 10:41:22 发布