const readline = require('readline');
const rl = readline.createInterface({
input : process.stdin,
output : process.stdout
});
const lines = [];
// input
rl.on('line', input => {
// 여기에서 input은 문제에 제시된 입력예시가 string형태로 한 줄씩이다
lines.push(input.split(' ').map(e => parseInt(e)))
})
// output
rl.on('close', () => {
// 출력예시대로 출력한다
console.log()
process.exit();
})
예를 들어 A+B를 구하는 코드를 짜보자
const readline = require('readline');
const rl = readline.createInterface({
input : process.stdin,
output : process.stdout
});
let sum = 0;
let array = [];
// input
rl.on('line', input => {
sum = input.split(' ').map((el) => parseInt(el)).reduce((acc, curr) => acc + curr, 0);
array.push(sum);
})
// output
rl.on('close', () => {
for (let i = 1; i < array.length; ++i) {
console.log(`Case #${i}: ${array[i]}`);
}
process.exit();
})
숫자.toFixed(n): 소수 n번째 자리까지 반올림한다
소수셋째자리에서 반올림하기
const num = 3.1465
const average = num.toFixed(2); // 소수점 둘째자리까지 반올림한다 3.15
'알고리즘' 카테고리의 다른 글
[Softeer] 장애물 인식 프로그램 JS (0) | 2024.01.29 |
---|---|
[Softeer] 금고털이 JS (0) | 2024.01.25 |
[Softeer] 강의실 배정 JS (그리디) (0) | 2024.01.25 |
[프로그래머스 LV2] 우박수열 JS (0) | 2024.01.19 |
[프로그래머스 LV3] 아이템 줍기 JS (0) | 2024.01.18 |