package cn;
public class Test05 {
public static void main(String[] args) {
//monkey select the king
boolean[] bs = new boolean[15];
for(int i=0;i<bs.length;i++){
bs[i] = true;
}
int count = 0; //用来计数,记录猴子报的数
int index = 0; //猴子的下标,代表第几个猴子
int monkeyLeft = 15; //剩下猴子的数量
while(monkeyLeft > 1){
if(bs[index]){
count++;
if(count == 7){
bs[index] = false;
monkeyLeft--;
count = 0;
}
}
index++;
if(index == 15){
index = 0;
}
}
for(int i=0;i<bs.length;i++){
if(bs[i]){
System.out.println(i+1);
}
}
}
}
猴子选大王
于 2019-09-18 22:46:00 首次发布