45 lines
1.3 KiB
Java
45 lines
1.3 KiB
Java
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Scanner;
|
|
public class YueSeFuHuan {
|
|
public static void main(String[] args) {
|
|
Scanner in = new Scanner(System.in);
|
|
while (in.hasNext()) {
|
|
int m = in.nextInt();
|
|
if (m <=1 || m>=100){
|
|
System.out.println("ERROR!");
|
|
continue;
|
|
}
|
|
Map<Integer, Integer> numList = new HashMap<>();
|
|
for (int i=1;i<=100;i++){
|
|
numList.put(i, i);
|
|
}
|
|
count(numList, m, 1, numList.size());
|
|
}
|
|
}
|
|
|
|
private static void count(Map<Integer, Integer> numList, int m, int step, int maxSize){
|
|
if (maxSize < m){
|
|
// 打印结果
|
|
StringBuilder sb = new StringBuilder();
|
|
for (Integer i =1;i<= maxSize;i++){
|
|
sb.append(numList.get(i)).append(",");
|
|
}
|
|
System.out.println(sb.toString().substring(0,sb.lastIndexOf(",")));
|
|
return;
|
|
}
|
|
int s = 1;
|
|
for (int i=1;i<= maxSize;i++){
|
|
if (step == m){
|
|
step = 1;
|
|
continue;
|
|
}
|
|
numList.put(s, numList.get(i));
|
|
step ++;
|
|
s ++;
|
|
}
|
|
count(numList, m, step, s-1);
|
|
}
|
|
}
|
|
|