import java.util.Set;
import java.util.TreeSet;
public class E {
public static Set<String> set = new TreeSet<String>();
public static void perm(char[] n, int begin, int end) {
if (begin == end) {
addNumber(String.valueOf(n));
} else {
for (int i = begin; i <= end; ++i) {
swap(n, begin, i);
perm(n, begin + 1, end);
swap(n, begin, i);
}
}
}
public static void swap(char[] n, int x, int y) {
if (x == y || n[x] == n[y]) {
return;
}
char temp = n[x];
n[x] = n[y];
n[y] = temp;
}
public static void addNumber(String str) {
if (str.charAt(2) == '4' || str.contains("35") || str.contains("53")) {
return;
}
set.add(str);
}
public static void main(String args[]) {
char[] number = new char[] { '1', '2', '3', '4', '5', '6' };
perm(number, 0, number.length - 1);
System.out.println(set.size());
int cols = 20;
for (String s : set) {
System.out.print(s + " ");
if (cols-- == 1) {
System.out.println();
cols = 20;
}
}
}
}
温馨提示:答案为网友推荐,仅供参考