Playground/자바문제집

[백준] 2164번

미숫가루설탕많이 2023. 4. 7. 09:57
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();   // 카드의 개수

        Queue<Integer> que = new LinkedList<>();
        for (int i = 1; i <= N; i++) {
            que.add(i);
        }

        while (que.size() > 1) {
            // 맨 위 카드 버리기
            que.poll();

            // 다음 맨 위 카드 맨 밑으로 넣어주기
            int temp = que.poll();
            que.add(temp);
        }
        System.out.println(que.poll());
    }
}
 

'Playground > 자바문제집' 카테고리의 다른 글

[백준] 1427번  (0) 2023.04.10
[백준] 11286번  (0) 2023.04.07
[프로그래머스] 피보나치 수  (0) 2023.04.07
[백준] 1874번  (0) 2023.04.06
[백준] 2750번  (0) 2023.04.06