본문 바로가기
백준 문제풀이

[백준]2164번

by Dodledd 2024. 4. 22.

아주 기초적인 Queue에 대한 문제이다.

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

public class b2164 {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        Queue<Integer> q = new LinkedList<>();

        int n = Integer.parseInt(bf.readLine());

        for(int i =1 ; i<=n ; i++){
                q.add(i);
        }

        while(q.size()!=1){
            q.poll();
            q.offer(q.poll());
        }
        System.out.println(q.peek());

    }
}

딱히 설명이 필요할 것 같지도 않다....

'백준 문제풀이' 카테고리의 다른 글

[백준]7568번  (0) 2024.04.29
[백준] 2941번  (0) 2024.04.27
[백준]11718  (0) 2024.04.21
[백준] 1009번  (0) 2024.04.20
[백준] 9012번  (0) 2024.04.18