Skip to content
On this page

백준 1373 JavaScript

수정하기
문서 생성 2021-11-04 22:47:59 최근 수정 2021-11-04 22:49:17
On this page

문제

백준 1373

풀이

const readFileSyncPath = require('path').basename(__filename).replace(/js$/, 'txt');
// const readFileSyncPath = '/dev/stdin';
let input = require('fs').readFileSync(readFileSyncPath).toString().trim();
input = input.split("").map(v => Number(v)).reverse();
let result = '';
let sum = 0;
let factor = 0;
input.forEach(v => {
if (factor === 3) {
result += sum.toString();
sum = 0;
factor = 0;
}
sum += Number(v * (2 ** factor));
factor++;
});
result += sum;
console.log(result.split("").reverse().join(""));