치춘 2022. 2. 4. 16:31

숫자

문제

두 양의 정수가 주어졌을 때, 두 수 사이에 있는 정수를 모두 출력하는 프로그램을 작성하시오.

입력

두 정수 A와 B가 주어진다.

출력

첫째 줄에 두 수 사이에 있는 수의 개수를 출력한다.

둘째 줄에는 두 수 사이에 있는 수를 오름차순으로 출력한다.

풀이

const num = () => {
  const fs = require("fs");
  let input = fs.readFileSync("/dev/stdin").toString().trim();
  const min =
    Number(input.split(" ")[0]) < Number(input.split(" ")[1])
      ? Number(input.split(" ")[0])
      : Number(input.split(" ")[1]);
  const max =
    Number(input.split(" ")[0]) > Number(input.split(" ")[1])
      ? Number(input.split(" ")[0])
      : Number(input.split(" ")[1]);
  let arr = [];

  if (max === min) console.log("0");
  else console.log(max - min - 1);
  for (let i = min + 1; i < max; i++) {
    arr.push(i);
  }
  console.log(arr.join(" "));
};

num();

반성회

맞았습니다!! 가 아니라 100점 으로 나오는 웃기는문제