forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbac1158.java
More file actions
57 lines (41 loc) · 1.24 KB
/
bac1158.java
File metadata and controls
57 lines (41 loc) · 1.24 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
import java.util.*;
public class bac1158 {
//[1] [2] [3] [4] [5] [6] [7]
//3, 6, 2, 7, 5, 1, 4
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
Queue<Integer> AnswerQueue = new LinkedList<>();
ArrayList<Integer> ArrList = new ArrayList<>();
for(int i=1; i<=N; i++)
{
AnswerQueue.offer(i);
}
while(!AnswerQueue.isEmpty())
{
if(AnswerQueue.size() == 1)
{
ArrList.add(AnswerQueue.poll());
break;
}
for(int j =1; j < K; j++)
{
// System.out.println("+" + AnswerQueue.peek());
AnswerQueue.offer(AnswerQueue.poll());
}
// System.out.println("-" + AnswerQueue.peek());
ArrList.add(AnswerQueue.poll());
}
//출력
System.out.print("<");
for(int i=0; i<ArrList.size(); i++)
{
if(i == ArrList.size()-1)
System.out.print(ArrList.get(i));
else
System.out.print(ArrList.get(i) + ", " );
}
System.out.print(">");
}
}