공부기록/백준

[백준] 2164번 카드2

메델 2023. 12. 13. 20:52
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;


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

    }
}