public class NumberRandom {
String[] stra = {"1", "2", "2", "3", "4", "5"};
int n = stra.length;
boolean[] visited = new boolean[n];
String result = "";
TreeSet<String> ts = new TreeSet<>();
int[][] a = new int[n][n];
private void searchMap() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
a[i][j] = 0;
} else {
a[i][j] = 1;
}
}
}
// 3 和 5 不能相连
a[3][5] = 0;
a[5][3] = 0;
// 开始遍历
for (int i = 0; i < n; i++) {
search(i);
}
Iterator<String> it = ts.iterator();
while (it.hasNext()) {
String str = it.next();
// 4 不能在第三位
if (str.indexOf("4") != 2) {
System.out.println(str);
}
}
}
private void se
用 1、2、2、3、4、5 这 6 个数字,用 Java 写一个 main 函数,打印出所有不同的排列,如:512234,412345 等,要求:“4“ 不能在第三位,“3“ 和“5“ 不能相连
最新推荐文章于 2023-02-15 16:07:20 发布


2511

被折叠的 条评论
为什么被折叠?



