All'alba vincerò

At dawn, I will win!

Algorithm

[백준] 1759번: 암호 만들기

나디아 Nadia 2024. 10. 18. 00:10

🛠️ 문제 

1759번: 암호 만들기

 

 

💡 풀이

const fs = require('fs');
const path = require('path');

const input = fs.readFileSync(path.join(__dirname, 'input.txt')).toString().trim().split('\n');


const [L, C] = input[0].split(' ').map(Number);
const letters = input[1].split(' ').sort();

const vowels = ['a', 'e', 'i', 'o', 'u'];
const result = [];

function isValid(combination) {
    let vowelCount = 0;
    let consonantCount = 0;

    for (const char of combination) {
        if (vowels.includes(char)) {
            vowelCount++;
        } else {
            consonantCount++;
        }
    }

    return vowelCount >= 1 && consonantCount >= 2;
}

function generateCombinations(start, combination) {
    if (combination.length === L) {
        if (isValid(combination)) {
            result.push(combination.join(''));
        }
        return;
    }

    for (let i = start; i < C; i++) {
        generateCombinations(i + 1, [...combination, letters[i]]);
    }
}

generateCombinations(0, []);
console.log(result.join('\n'));

 

 

 

Algorithm-study/Algorithm/Solving/Backtracking/1759.js at main · kwonboryong/Algorithm-study

알고리즘(algorithm) 문제 풀이 스터디 . Contribute to kwonboryong/Algorithm-study development by creating an account on GitHub.

github.com

 

3주차 - 5일 | Notion

💡문제 분석 요약

thin-brisket-ae4.notion.site