File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ N장의 카드가 있다. 각각의 카드는 차례로 1부터 N까지의 번호가 붙어 있으며,
3
+ 1번 카드가 제일 위에, N번 카드가 제일 아래인 상태로 순서대로 카드가 놓여 있다.
4
+
5
+ 제일 위에 있는 카드를 바닥에 버린다.
6
+ 그 다음, 제일 위에 있는 카드를 제일 아래에 있는 카드 밑으로 옮긴다.
7
+
8
+ queue의 poll, offer
9
+ */
10
+
11
+ // 시간: 15:21
12
+
13
+ import java .util .*;
14
+ import java .util .stream .*;
15
+ import java .io .*;
16
+
17
+ public class Boj2164 {
18
+
19
+ public static void main (String ...args ) throws Exception {
20
+ var br = new BufferedReader (new InputStreamReader (System .in ));
21
+ var input = Integer .parseInt (br .readLine ());
22
+
23
+ if (input == 1 ){
24
+ System .out .println (1 );
25
+ return ;
26
+ }
27
+ var queue = IntStream .range (1 , input + 1 )
28
+ .mapToObj (Integer ::valueOf )
29
+ .collect (Collectors .toCollection (LinkedList ::new ));
30
+
31
+ while (queue .size () > 2 ){
32
+ queue .poll (); //drop card
33
+ queue .offer (queue .poll ());
34
+ }
35
+
36
+ queue .poll ();
37
+ System .out .println (queue .poll ());
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments