문제 자체는 쉬웠다.
숫자를 나눴을때 몫과 나머지를 구하는 문제였으니까.
그런데 1가지 명심해야 할 것이 있었다.
그것은 프로토스도 찾아올 정도로 돈이 아주 많은 부자라는 점이다.
const [money, people] = require("fs")
.readFileSync("/dev/stdin")
.toString()
.trim()
.split(" ")
.map((i) => parseInt(i));
let remain = money / people;
let share = money % people;
console.log(remain, share);
처음에는 백준에 이렇게 제출했다.
그랬더니 4초만에 틀렸다고 출력되었다.
혹시 출력이 잘못된거가 싶어서
const [money, people] = require("fs")
.readFileSync("/dev/stdin")
.toString()
.trim()
.split(" ")
.map((i) => parseInt(i)).map(BigInt);;
const remain = money / people;
const share = money % people;
console.log(remain);
console.log(share);
요로코롬 고쳤더니 런타임 에러 (RangeError)가 출력되었다.
찾아보니 어떤값이 집합에 없거나 허용되는 범위가 아닐때 나타나는 오류였다.
문제를 다시 읽으니 프로토스도 찾아올 정도로 이 부자는 돈이 많은 사람이였다.
Javascript의 큰수를 검색하니 내장객체은 BingInt()에 대해 알수 있었다.
const [money, people] = require("fs")
.readFileSync("1271.txt")
.toString()
.trim()
.split(" ")
.map((i) => parseInt(i));
money = BigInt(input.shift()); // 1000n
people = BigInt(input.shift()); // 100n
let remain = money / people;
let share = money % people;
console.log(remain);
console.log(share);
그랬더니 런타임에러(ENOENT)에러가 나타났다(...)
파일 또는 그런 디렉토리가 없다는 오류인데 입력값을 잘못 적었다(....)
하지만 입력값을 바꾸니 이번엔 ReferenceError가 뜨는(...)
환장의 시대가 열렸다.
출력값이 이상한건가 싶어서
console.log((money / people).toString());
console.log((money % people).toString());
출력값을 오로코롬 바꿨는데 다시 런타임에러(RangeError)가 나왔다.
흠.. 뭐지 싶어서
const input = require("fs")
.readFileSync("/dev/stdin")
.toString()
.trim()
.split(" ")
const money = BigInt(input.shift()); // 1000n
const people = BigInt(input.shift()); // 100n
console.log((money / people).toString());
console.log((money % people).toString());
코드를 이렇게 수정했더니 맞았다고 한다.
아마 내생각으로는 배열이 아닌데 map을 돌려서 오류가 난게 아닐까 생각한다.
쉬운문제이긴 한데 조금 구현하는 과정에서 조금 까다롭다고 생각한다.
내가 못해서 일수도 있지만(뀨)
이 문제로 알게된 점은
라는 것이다.
의식적으로 행동을 천천히 하는 습관을 들여야겠다.