관리 메뉴

Silver Library (Archived)

백준 JS 소스코드 템플릿 겸 - 2588 곱셈 본문

CS Library/JavaScript - Data Structure

백준 JS 소스코드 템플릿 겸 - 2588 곱셈

Chesed Kim 2021. 7. 19. 11:59
반응형

여기서 알게된 사실이 있는게, 이 백준 사이트에서 풀때 쓰기 좋은 코드블럭 '템플릿' 이 있었다는 점 입니다.

 

Template 1.

const readline = require("readline"):
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
}):

const input = []: // 변수를 저장
rl.on("line", function(line) { // line 이라는 변수를 입력
    input.push(line) // 한 줄씩 입력받고 무한으로 입력받음

}).on("close", function() { // 컨트론 + D 누르면 종료 (백준은 입력 끝나면 자동 종료)
    solution(input): // 원하는 함수 실행
    process.exit():
}):

 

 

그리고 이를 토대로 나온 해답은:

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

const solution = (a,b) => {
    c1 = parseInt(a);
    c2 = new Array(b[0], b[1], b[2]).map( a => parseInt(a) );
    c3 = c1*c2[2];
    c4 = c1*c2[1];
    c5 = c1*c2[0];
    c6 = c3+c4*10+c5*100;
    console.log(c3);
    console.log(c4);
    console.log(c5);
    console.log(c6);
}

const input = [];
rl.on("line", function(line) {
    input.push(line)
}).on("close", function() {
    solution(input[0], input[1]);
    process.exit();
});

 

메모:

Array 부분을 보고 나서 다시 재도전 해 봐야 겠습니다.

 

 

 

 

 

출처: https://zereight.tistory.com/715 [Zereight's Blog]

'CS Library > JavaScript - Data Structure' 카테고리의 다른 글

9498 번 JS, 풀어보자.  (0) 2021.07.19
백준 1330번 JS - closure, node.js template?  (0) 2021.07.19
class in JS  (0) 2021.07.18
Callback in JS?  (0) 2021.07.17
Constructor, super class, literal, static  (0) 2021.07.17