Development/Program Solving
-
[백준 10872번] 팩토리얼 (feat. NodeJS)Development/Program Solving 2021. 1. 7. 02:05
10872번: 팩토리얼 0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오. www.acmicpc.net 문제 0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오. 풀이 3! = 3 * 2 * 1 2! = 2 * 1 이런식으로 연산하는 것을 팩토리얼이라고 한다. n-1을 곱하는 것이 반복되므로 재귀를 사용해서 알고리즘을 작성하면 된다. const fs = require("fs"); const input = fs.readFileSync("/dev/stdin"); const n = parseInt(input); const getFactorial = (n) => { if (n === 1 || n === 0) { return 1; } retur..
-
[백준 10870번] 피보나치 수 (feat. NodeJS)Development/Program Solving 2021. 1. 7. 01:37
10870번: 피보나치 수 5 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가 www.acmicpc.net 문제 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가 된다. n=17일때 까지 피보나치 수를 써보면 다음과 같다. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597 n이 주어..
-
[백준 2292번] 벌집 (feat. NodeJS)Development/Program Solving 2021. 1. 6. 02:27
2292번: 벌집 위의 그림과 같이 육각형으로 이루어진 벌집이 있다. 그림에서 보는 바와 같이 중앙의 방 1부터 시작해서 이웃하는 방에 돌아가면서 1씩 증가하는 번호를 주소로 매길 수 있다. 숫자 N이 주어졌 www.acmicpc.net 범위가 1, 2~7, 8~19, 20~37, 38~61로 증가한다. 공식으로 나타내면 이전값 + 범위카운트 * 6 이다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let input; const onInput = (value) => (input = Number(value)); const on..
-
[백준 1712번] 손익분기점 (feat. NodeJS)Development/Program Solving 2021. 1. 6. 01:12
1712번: 손익분기점 월드전자는 노트북을 제조하고 판매하는 회사이다. 노트북 판매 대수에 상관없이 매년 임대료, 재산세, 보험료, 급여 등 A만원의 고정 비용이 들며, 한 대의 노트북을 생산하는 데에는 재료비와 www.acmicpc.net 아래와 같이 무한루프를 돌려서 1씩 수량을 증가시켜서 했더니, 시간초과 결과가 나왔다. 입력이 21억 이하이므로 이런식으로 무한루프를 사용한 알고리즘을 작성하면 안된다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let input; const onInput = (value) => (inp..
-
[백준 단계별로 풀어보기] 7. 문자열 (feat. NodeJS)Development/Program Solving 2020. 12. 29. 03:08
11654번: 아스키 코드 const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let inputValue; const onInput = (value) => (inputValue = value); const onClose = () => { const result = []; for (let i = 0; i < 26; i++) { result[i] = inputValue.indexOf(String.fromCharCode(i + 97)); } console.log(result.join(" ")); process.exit(); }; rl.on..
-
[백준 단계별로 풀어보기] 6. 함수 (feat. NodeJS)Development/Program Solving 2020. 12. 27. 22:56
4673번: 셀프 넘버 4673번: 셀프 넘버 셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌을 때, www.acmicpc.net CASE 1 시간: 108.917ms const selfNumber = []; const main = () => { for (let i=1; i { for (let i=1; i number = Number(input); const onClose = () => { let firstNum = 0; let answer = []; for (let i = 1; i = 3){ const numbers..
-
[백준 단계별로 풀어보기] 3. for문 (feat.NodeJS)Development/Program Solving 2020. 12. 25. 02:22
2739번: 구구단 2739번: 구구단 N을 입력받은 뒤, 구구단 N단을 출력하는 프로그램을 작성하시오. 출력 형식에 맞춰서 출력하면 된다. www.acmicpc.net 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 array.push(input); const onClose = () => { for(let i=1; i number = Number(in..
-
[백준 단계별로 풀어보기] 5. 1차원 배열 (feat.NodeJS)Development/Program Solving 2020. 12. 25. 00:23
10818번: 최소, 최대 10818번: 최소, 최대 첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다. www.acmicpc.net CASE 1 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 ..