알고리즘

2164 큐

초코푸딩 2022. 9. 13. 13:53
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class P2164 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Queue<Integer> que = new LinkedList<>();
        int N = scan.nextInt();
        for(int i=1; i<=N; i++) {
            que.add(i);
        }
        while(que.size() > 1) {
            que.poll();
            que.add(que.poll());
        }
        System.out.println(que.poll());
    }
}