백준-Node.js-2338, 긴자리 계산

송철진·2023년 2월 10일
0

백준-Node.js

목록 보기
12/69

풀이

const fs = require('fs')
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n')
const [a, b] = [ BigInt(input[0]), BigInt(input[1]) ]

console.log( [a+b, a-b, a*b].join('\n') )

BigInt()를 쓰면 긴자리 숫자도 생략된 거 없이 계산할 수 있다.
단, 주어진 조건을 만족하려면 'n'이 안보여야 하므로 문자열 타입으로 변환한다.
toString()도 할 수 있지만 개행문자(\n)를 기준으로 join()해서 문자열 타입으로 변환했다.

profile
검색하고 기록하며 학습하는 백엔드 개발자

0개의 댓글