반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Algorithm
- 그래프
- dfs
- BFS
- Nestjs
- 쉬운 문제
- 소켓
- dp
- 타입스크립트
- type challenge
- 크롤링
- Crawling
- 레벨 1
- HTTP 완벽 가이드
- 프로그래머스
- socket
- 가천대
- Node.js
- javascript
- 자바스크립트
- typescript
- 타입 챌린지
- HTTP
- ip
- 백준
- 수학
- 문자열
- TCP
- 프로그래머스 레벨 2
- 알고리즘
Archives
- Today
- Total
kakasoo
[node.js] 다리 놓기 ( 백준 1010번 ) 본문
반응형
부분 문자열, 부분 수열과 같다고 생각하면 되겠다.
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let count = 0;
const input = [];
rl.on("line", (line) => {
if (!count) {
count = Number(line);
} else {
input.push(line);
if (input.length === count) {
main(line);
rl.close();
}
}
}).on("close", () => {
process.exit();
});
const factorial = (num) => {
if (num === 1 || num === 0) {
return 1;
}
return num * factorial(num - 1);
};
const main = () => {
input.forEach((el) => {
const numbers = el
.split(" ")
.map(Number)
.sort((a, b) => a - b);
const min = numbers[0];
const max = numbers[1];
const answer = factorial(max) / (factorial(min) * factorial(max - min));
console.log(parseInt(answer + 0.5));
});
};
반응형
'프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
[node.js] 가장 긴 증가하는 부분 수열 ( 백준 11053번 ) (0) | 2021.03.30 |
---|---|
[node.js] 균형잡힌 세상 ( 백준 4949번 ) (0) | 2021.03.30 |
[node.js] 잃어버린 괄호 (백준 1541번) (0) | 2021.03.30 |
[node.js] 포도주 시식 ( 백준 2165번 ) (0) | 2021.03.29 |
[node.js] 평범한 배낭 ( 백준 12865번 ) (0) | 2021.03.26 |