백준 - 11866 요세푸스

jihyun·2025년 1월 12일

풀자

목록 보기
6/6

문제 https://www.acmicpc.net/problem/11866

const fs = require('fs');
const input = fs.readFileSync(0, 'utf-8').trim();

const [all, num] = input.split(' ').map(Number);
const result = [];
let idx = 0;

const newAll = Array.from({length: all}, (v,i) => i + 1);

while (newAll.length > 0){
    idx = (idx + num - 1) % newAll.length;
    result.push(newAll.splice(idx, 1)[0]);
}
console.log('<' + result.join(', ') + '>');

연결 리스트

splice

splice() 메서드는 배열의 기존 요소를 삭제 또는 교체하거나 새 요소를 추가하여 배열의 내용을 변경합니다.
splice하면 Array가 변경되고 제거한 요소의 배열을 반환한다.

0개의 댓글