1.有n个小朋友围一圈喊口号,喊到3出列,继续喊直到最后一个
import java.util.*;
/**
* @ClassName Stank
* @Description 有n个小朋友围一圈喊口号,喊到3出列,继续喊直到最后一个。
* @Author 王琛
* @Date 2019/10/21 18:35
* @Version 1.0
*/
//思路使用双向循环队列
public class Stank {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int count = 1;
Inte listH = new Inte();
listH.setBefore(listH);
listH.setI(1);
listH.setNext(listH);
for(int i =2; i <= n; i++){
Inte listB = new Inte();
listB.setI(i);
listH.before.setNext(listB);
listB.setNext(listH);
listB.setBefore(listH.before);
listH.setBefore(listB);
}
Inte p = listH;
while (p.getI()!=p.getNext().getI()){
if(count!=3){
count++;
p=p.next;
}else{
System.out.println(p.before.getI()+"========"+p.getI()+"====="+p.next.getI());
Inte B = p.next;
p.before.setNext(p.next);
p.next.setBefore(p.before);
p=B;
count=1;
}
}
System.out.println(p.getI());
}
}
class Inte{
public int i ;
public Inte next;
public Inte before;
public Inte getBefore() {
return before;
}
public void setBefore(Inte before) {
this.before = before;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public Inte getNext() {
return next;
}
public void setNext(Inte next) {
this.next = next;
}
}