[AppleScript] 纯文本查看 复制代码 public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<Integer>();
for(int x=1;x<=n;x++){//有多少个人就把n改成多少
al.add(x);
}
int result = deleteEle(al);
System.out.println(result);
}
private static int deleteEle(ArrayList<Integer> al) {
int index = -1;
while(al.size() != 1){
//3次循环相当于一轮,循环结束后的角标即为踢出的学生
for(int x=0;x<3;x++){
index++;
//若角标等于剩余人数时,从0计起,如此循环
if(index>=al.size()){
index = 0;
}
}
al.remove(index);
index--;
}
return al.get(0);
} |