1158번 요세푸스 문제

han.user();·2023년 3월 30일
0

백준 온라인 저지

목록 보기
7/7
post-thumbnail

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] input = sc.nextLine().split(" ");
        int N = Integer.parseInt(input[0]);
        int K = Integer.parseInt(input[1]);

        sc.close();

        ArrayList<Integer> people = new ArrayList<Integer>();
        for (int i = 1; i <= N; i++) {
            people.add(i);
        }

        int idx = 0;

        System.out.print("<");
        while (people.size() > 1) {
            idx = (idx + K - 1) % people.size();
            System.out.print(people.remove(idx) + ", ");
        }
        System.out.print(people.get(0));
        System.out.println(">");
    }
}
profile
I'm still hungry.

0개의 댓글