본문 바로가기
알고리즘 (with. 백준 문제풀이)/Queue

백준 2161번 [카드1]

by 천릉객 2023. 9. 18.
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split();

const n = Number(input[0]);

let arr = Array.from(new Array(n), (x, i) => i+1);

let answer = [];

while(arr.length > 0){
    answer.push(arr.shift());
    if (arr.length > 0) {
        arr.push(arr.shift());
    }
}

str = answer.join(" ")
console.log(str)