Algorithm

[Algorithm] BOJ 1158

by Donghwan 2021. 7. 28.
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Queue<Integer> queue = new LinkedList<>();
        StringBuffer sb = new StringBuffer();
        int n = sc.nextInt();
        int k = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            queue.offer(i);
        }

        int index = 1;
        sb.append("<");
        while (!queue.isEmpty()) {
            int a = queue.poll();
            if ((index++ % k) != 0) {
                queue.offer(a);
            } else {
                sb.append(a + (queue.isEmpty() ? "" : ", "));
            }
        }
        sb.append(">");
        System.out.print(sb);
    }
}
728x90
반응형

'Algorithm' 카테고리의 다른 글

[Algorithm] 삽입정렬  (0) 2021.11.26
[Algorithm] 선택정렬  (0) 2021.11.26
[Algorithm] Vector  (0) 2021.10.06
[Algorithm] Stack  (0) 2021.09.21
[Algorithm] BOJ 1260  (0) 2021.07.28

댓글