-
[백준 단계별로 풀어보기] 3. for문 (feat.NodeJS)Development/Program Solving 2020. 12. 25. 02:22728x90
2739번: 구구단
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let number; const onInput = (input) => number = Number(input); const onClose = () => { for(let i=1; i<=9; i++) { console.log(`${number} * ${i} = ${number * i}`) } process.exit(); } rl.on('line', onInput) .on('close', onClose);
10950번: A+B -3
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const array = []; const onInput = (input) => array.push(input); const onClose = () => { for(let i=1; i<=array[0]; i++) { const [num1, num2] = array[i].split(" "); console.log(Number(num1) + Number(num2)); } process.exit(); } rl.on('line', onInput) .on('close', onClose);
8393번: 합
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let number; const onInput = (input) => number = Number(input); const onClose = () => { let answer = 0; for(let i=1; i<=number; i++){ answer += i; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
15552번: 빠른 A+B
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const array = []; let answer = ''; const onInput = (input) => array.push(input); const onClose = () => { for(let i=1; i<=array[0]; i++) { const [num1, num2] = array[i].split(" "); answer += `${Number(num1) + Number(num2)}\n`; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
2741번: N 찍기
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let answer = ''; let number; const onInput = (input) => number = Number(input); const onClose = () => { for(let i=1; i<=number; i++) { answer += `${i}\n`; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
2742번: 기찍 N
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let answer = ''; let number; const onInput = (input) => number = Number(input); const onClose = () => { for(let i=number; i>=1; i--) { answer += `${i}\n`; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
11021 번: A+B - 7
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const array = []; let answer = ''; const onInput = (input) => array.push(input); const onClose = () => { for(let i=1; i<=array[0]; i++) { const [num1, num2] = array[i].split(" "); answer += `Case #${i}: ${Number(num1) + Number(num2)}\n`; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
11022번: A+B - 8
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const array = []; let answer = ''; const onInput = (input) => array.push(input); const onClose = () => { for(let i=1; i<=array[0]; i++) { const [num1, num2] = array[i].split(" "); answer += `Case #${i}: ${num1} + ${num2} = ${Number(num1) + Number(num2)}\n`; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
2438번: 별 찍기 - 1
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let answer = ''; let number; const onInput = (input) => number = Number(input); const onClose = () => { for(let i=1; i<=number; i++){ for(let y=0; y<i; y++){ answer += '*'; } answer += '\n'; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
2439번: 별 찍기 - 2
CASE 1
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let answer = ''; let number; let star = ''; const onInput = (input) => number = Number(input); const onClose = () => { for(let i=1; i<=number; i++){ for(let y=0; y<i; y++){ star += '*'; } answer += `${star.padStart(number)}\n`; star = ''; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
CASE 2
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let answer = ''; let number; const onInput = (input) => number = Number(input); const onClose = () => { for(let i=1; i<=number; i++){ answer += " ".repeat(number-i) + "*".repeat(i) + '\n'; } console.log(answer); process.exit(); } rl.on('line', onInput) .on('close', onClose);
10871번: X보다 작은 수
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const array = []; const onInput = (input) => array.push(input); const onClose = () => { const [a, b] = array; const [n, x] = a.split(" "); const answer = b.split(" ").filter(number => Number(number) < Number(x)); console.log(answer.join(" ")); process.exit(); } rl.on('line', onInput) .on('close', onClose);
728x90'Development > Program Solving' 카테고리의 다른 글
[백준 단계별로 풀어보기] 7. 문자열 (feat. NodeJS) (0) 2020.12.29 [백준 단계별로 풀어보기] 6. 함수 (feat. NodeJS) (0) 2020.12.27 [백준 단계별로 풀어보기] 5. 1차원 배열 (feat.NodeJS) (0) 2020.12.25 [백준 단계별로 풀어보기] 2. if문 (feat.NodeJS) (0) 2020.12.23 [백준 단계별로 풀어보기] 1.입출력과 사칙연산 (feat.NodeJS) (0) 2020.12.20