본문 바로가기

Algorithm/백준

백준2164 카드2

public class Boj2164 {
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        Queue<Integer> qe = new LinkedList<>();
        for(int i = 1; i <= n ; i++){
            qe.offer(i);
        }
        while(qe.size() > 1){
            qe.poll();
            qe.offer(qe.poll());
        }
        System.out.println(qe.poll());

    }
}

'Algorithm > 백준' 카테고리의 다른 글

백준 12789 도키도키 간식드리미  (0) 2024.07.25
백준 11866 요세푸스문제 0  (0) 2024.07.25
백준 1158 요세푸스 문제  (0) 2024.07.25
백준 1018 체스판 다시 칠하기  (0) 2024.06.28
백준 25206 너의 평점은  (0) 2024.06.28