-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ1158.java
More file actions
95 lines (79 loc) · 2.1 KB
/
Copy pathJ1158.java
File metadata and controls
95 lines (79 loc) · 2.1 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package TIL;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;
class MyNode{
Integer data;
MyNode next;
public MyNode(Integer data){
this.data = data;
this.next = null;
}
}
class MyList{
private MyNode head;
private MyNode tail;
public MyList() {
this.head = null;
this.tail = null;
}
public void add(Integer data){
MyNode myNode = new MyNode(data);
if(head == null){
head = myNode;
tail = myNode;
} else {
tail.next = myNode;
tail = myNode;
}
}
public Integer remove(Integer data){
if(data == 0) {
Integer num = head.data;
head = head.next;
if(head == null) tail = null;
return num;
}
// end point remove
MyNode cur = head;
for(int i = 0 ; i < data-1; i++){
cur = cur.next;
}
Integer num = cur.next.data;
cur.next = cur.next.next;
if(cur.next == null) tail = cur;
return num;
}
public boolean isEmpty(){
return head == null;
}
}
public class J1158 {
static int size = 0;
public static void main(String[] args) throws IOException {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String[] input = buffer.readLine().split(" ");
MyList myList = new MyList();
int n = Integer.parseInt(input[0]);
int k = Integer.parseInt(input[1]);
for(int i = 1 ; i <= n; i++){
myList.add(i);
size++;
}
int index = k-1;
System.out.print("<");
while(!myList.isEmpty()){
index = index % size;
int remove = myList.remove(index);
System.out.print(remove);
size--;
if(!myList.isEmpty()){
System.out.print(", ");
}
index = index + k - 1;
}
System.out.print(">");
System.out.println();
}
}