
const fs = require('fs');
const input = fs
.readFileSync('/dev/stdin')
.toString()
.trim()
.split(' ')
.map((it) => BigInt(it));
let a, b;
if (input[0] < input[1]) {
a = input[0];
b = input[1];
} else {
a = input[1];
b = input[0];
}
const answer = [];
for (let i = a + 1n; i < b; i++) answer.push(i.toString());
if (a !== b) {
console.log((b - a - 1n).toString());
console.log(...answer);
} else {
console.log(0);
}
나는 bigint썼는데 다른 스터디원 말을 들어보니 안써도 된다고 하신다.
어찌되었던, 숫자 뒤에 n을 붙여주면 BigInt를 다룰수 있다.
아래는 같이 알고리즘 문제풀이를 진행하는 @정욱님 의 소스코드인데 bigint를 사용하지 않은 모습!
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString();
const numbers = input.split(' ').map(str => Number.parseInt(str, 10));
const sorted = [...numbers];
sorted.sort((a, b) => a - b);
const [first, second] = sorted;
if (first === second) {
console.log(0);
} else {
console.log(second - first - 1);
}
for (let i = first + 1; i < second; i++) {
process.stdout.write(`${i} `);
}