728x90
Line:31
idx = (idx>list.size())?idx%list.size() : idx;
->(수정)
idx = (idx>=list.size())?idx%list.size() : idx;
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
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Main {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException{
String[] str = br.readLine().split(" ");
int N = stoi(str[0]);
int K = stoi(str[1]);
LinkedList<Integer> list = new LinkedList<>();
for(int i=1; i<=N; i++)
list.add(i);
int idx = -1;
List<Integer> res = new ArrayList<>();
while(!list.isEmpty()) {
idx += K;
idx = (idx>=list.size())?idx%list.size() : idx;
res.add(list.remove(idx--));
}
bw.write("<");
for (int i=0; i<res.size()-1; i++) {
bw.write(res.get(i)+", ");
}
bw.write(res.get(res.size()-1)+"");
bw.write(">");
bw.flush();
bw.close();
}
private static int stoi(String input) {
return Integer.parseInt(input);
}
}
|
cs |
'알고리즘 풀이 > 백준' 카테고리의 다른 글
[백준][Java] 2661번 좋은수열 (백트래킹) (0) | 2021.10.05 |
---|---|
[백준][Java] 11723번 집합 (비트마스크) #2 (0) | 2021.10.05 |
[백준][Java] 1759번 암호 만들기 (백트래킹, 브루트포스) (0) | 2021.10.04 |
[백준][Java] 1182번 부분수열의 합 (백트래킹, 브루트포스) (0) | 2021.10.03 |
[백준][Java] 2448번 별 찍기 - 11 (분할정복, 재귀) #2 (0) | 2021.10.03 |