您的位置:首页 > 其它

Exercise1_3_37

2016-02-05 20:18 253 查看
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));
}
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: