BOJ_3단계 2742번 기찍 N

Daniel Lim·2021년 5월 11일
0

문제풀이

목록 보기
15/19
post-thumbnail

2741번 N찍기와 비슷한 문제이다.
주어진 숫자부터 1이 될때까지 1씩 점점 줄어드는걸 출력하면 됨.

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let result = '';
let number;

const onInput = (input) => number = Number(input);

const onClose = () => {
    for(let i=number; i>=1; i--) {  
      // 주어진 숫자부터 출력하기때문에 초기값은 number와 같아야한다.
      // 1이 될때까지 출력하고, 1씩 줄어들게 설정했다.
        result += `${i}\n`;
    }
    console.log(result);
    
    process.exit();
}

rl.on('line', onInput).on('close', onClose);
profile
웹개발 잘하고 싶어요

0개의 댓글