-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1158.java
More file actions
30 lines (25 loc) · 851 Bytes
/
1158.java
File metadata and controls
30 lines (25 loc) · 851 Bytes
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
import java.io.*;
import java.util.LinkedList;
import java.util.Queue;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int n = Integer.parseInt(input[0]);
int k = Integer.parseInt(input[1]);
Queue<Integer> queue = new LinkedList<>();
for (int i = 1; i <= n; i++) {
queue.offer(i);
}
StringBuilder sb = new StringBuilder();
sb.append("<");
while (queue.size() > 1) {
for (int j = 1; j < k; j++) {
queue.offer(queue.poll());
}
sb.append(queue.poll()).append(", ");
}
sb.append(queue.poll()).append(">");
System.out.print(sb);
}
}