Algorithm

[Algorithm] BOJ 1158

Donghwan 2021. 7. 28. 18:36
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
반응형