-
Notifications
You must be signed in to change notification settings - Fork 0
/
Card_1.java
35 lines (26 loc) · 962 Bytes
/
Card_1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Deque;
import java.util.LinkedList;
public class Card_1 {
private static Deque<Integer> resultDeque = new LinkedList<>();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
initResultDeque(N);
while(resultDeque.size() >= 2) {
int deleteValue = resultDeque.pollFirst();
int offerValue = resultDeque.pollFirst();
resultDeque.offerLast(offerValue);
sb.append(deleteValue).append(" ");
}
sb.append(resultDeque.pollFirst());
System.out.println(sb);
}
private static void initResultDeque(int N) {
for(int i = 1; i <= N; i++) {
resultDeque.offer(i);
}
}
}