๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 6603๋ฒ] ๋ก๋ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon
2022. 2. 6. 18:56
728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/6603
const fs = require('fs');
let input = fs
.readFileSync('dev/stdin')
.toString()
.trim()
.split('\n')
.map((v) => v.split(' '));
input.pop();
const getCombinations = function (arr, selectNum) {
const results = [];
if (selectNum === 1) return arr.map((value) => [value]);
arr.forEach((fixed, index) => {
const rest = arr.slice(index + 1);
const combinations = getCombinations(rest, selectNum - 1);
const attached = combinations.map((combination) => [fixed, ...combination]);
results.push(...attached);
});
return results;
};
input = input.map((v) => v.slice(1));
for (let i = 0; i < input.length; i++) {
getCombinations(input[i], 6).forEach((v) => {
console.log(v.join(' '));
});
console.log('');
}
์กฐํฉ์ ์ฌ์ฉํด ์ฝ๊ฒ ํ ์ ์๋ค.
728x90
๋ฐ์ํ