/////////
Search
🃏

백준 2164 카드2

import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class StackQueue02 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Queue<Integer> q = new LinkedList<>(); for(int i=1;i<=n;i++) { q.offer(i); // 1~n까지의 값을 q에 저장 } while(q.size()>1) { q.poll(); // q에서 추출한 값을 int temp = q.poll(); // temp에 저장한 후 q.offer(temp); // } System.out.println(q.poll()); } }
Java
복사