package chapterone;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Josephus {
public static void main(String[] args) {
Queue<Integer> queue = new LinkedList<Integer>();
System.out.println("start");
System.out.println("————————————————");
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int M = scan.nextInt();
scan.close();
for (int i = 0; i < N; i++) {
queue.add(Integer.valueOf(i));
}
int k = 0;
while (!queue.isEmpty()) {
int x = queue.poll();
if ((++k) % M == 0) {
System.out.print(x + " ");
} else {
queue.add(Integer.valueOf(x));
}
}
}
}
Exercise1_3_37
最新推荐文章于 2022-02-13 00:19:35 发布