Skip to content

Conversation

@froglike6
Copy link
Collaborator

@froglike6 froglike6 commented Jul 9, 2025

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

20๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

์ˆ˜๋„ ์ฝ”๋“œ

์ž…๋ ฅ L, C

letters๋ฅผ ์ฝ์–ด ์‚ฌ์ „์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค

vowels ์ง‘ํ•ฉ์„ {'a', 'e', 'i', 'o', 'u'}๋กœ ์ •์˜ํ•œ๋‹ค

letters์—์„œ ๊ธธ์ด๊ฐ€ L์ธ ๋ชจ๋“  ์กฐํ•ฉ combo๋ฅผ ์ฐจ๋ก€๋กœ ํ™•์ธํ•œ๋‹ค:
    v_cnt โ† combo ์•ˆ์— ํฌํ•จ๋œ ๋ชจ์Œ์˜ ๊ฐœ์ˆ˜

    ๋งŒ์•ฝ v_cnt๊ฐ€ 1 ์ด์ƒ์ด๊ณ :
        L - v_cnt๊ฐ€ 2 ์ด์ƒ์ด๋ผ๋ฉด:
            combo๋ฅผ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ์ด์–ด์„œ ์ถœ๋ ฅํ•œ๋‹ค
    ๊ทธ ์™ธ์˜ ๊ฒฝ์šฐ:
        ์•„๋ฌด ๊ฒƒ๋„ ์ถœ๋ ฅํ•˜์ง€ ์•Š๊ณ  ๋‹ค์Œ ์กฐํ•ฉ์„ ๊ฒ€์‚ฌํ•œ๋‹ค

๋ฒŒ์จ 20๋ฒˆ์งธ pr์ด๋„ค์š”...๐Ÿฅน๐Ÿฅน ์ตœ๊ทผ ๋ฌธ์ œ๋“ค์„ ๋ณด๋‹ค ๋ณด๋‹ˆ, ๋„ˆ๋ฌด ์–ด๋ ค์šด ๊ฒƒ๋“ค์ด ๋งŽ์•„ ์‰ฌ์šด ๋ฌธ์ œ๋ฅผ ๋“ค๊ณ  ์™”์Šต๋‹ˆ๋‹ค.
์ด ๋ฌธ์ œ๋Š” ๊ฐ€๋Šฅํ•œ ์กฐ๊ฑด์˜ ๋ฌธ์ž์—ด์„ ๋ชจ๋‘ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ๊ฐ€๋Šฅํ•œ ์กฐ๊ฑด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ์„œ๋กœ ๋‹ค๋ฅธ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ๊ตฌ์„ฑ๋จ
  • ์ตœ์†Œ ํ•œ ๊ฐœ์˜ ๋ชจ์Œ๊ณผ ์ตœ์†Œ ๋‘ ๊ฐœ์˜ ์ž์Œ์œผ๋กœ ๊ตฌ์„ฑ๋จ
  • ์•ŒํŒŒ๋ฒณ์ด ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์„œ๋กœ ๋ฐฐ์—ด๋จ

์œ„์˜ 3๊ฐ€์ง€๋ฅผ ๋ชจ๋‘ ๋งŒ์กฑํ•˜๋Š” ๋ฌธ์ž์—ด์„ ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•˜๋ฉด ๋˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
์ €๋Š” ํŒŒ์ด์ฌ์˜ combinations์„ ์‚ฌ์šฉํ•ด์„œ ๋‹ค๋ฅธ ์–ธ์–ด๋ณด๋‹ค ๋น„๊ต์  ์‰ฝ๊ฒŒ ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.

for์—์„œ ๊ฐ€๋Šฅํ•œ ์กฐํ•ฉ์„ ๋Œ๋ฉด์„œ ๋ชจ์Œ์˜ ๊ฐœ์ˆ˜๋ฅผ ์ƒˆ๊ณ , ๋‘ ๋ฒˆ์งธ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š”์ง€ ์ฒดํฌํ•œ ํ›„ ์ถœ๋ ฅํ•˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ž…๋ ฅ ๋ฐ›์„ ๋•Œ๋ถ€ํ„ฐ letters๋ฅผ ์ •๋ ฌํ•ด์„œ, ๋ณ„๋„์˜ ์ •๋ ฌ ์—†์ด ๋ฐ”๋กœ ์‚ฌ์ „ ์ˆœ ์ถœ๋ ฅ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

@Fnhid
Copy link
Collaborator

Fnhid commented Jul 11, 2025

์–ด..์‰ฌ์šด ๊ฑฐ ๋งž๋‚˜์š”

์ „ ์กฐ๊ฑด์„ ์ž˜๋ชป ์ฝ์–ด์„œ(๊ทธ๋ƒฅ ์กฐํ•ฉ์— ๋ชจ์Œ ์ตœ์†Œ ํ•˜๋‚˜๋งŒ ์žˆ์œผ๋ฉด ๋˜๋Š” ์ค„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค.)
์‚ฝ์งˆ์„ ์ข€ ๊ธธ๊ฒŒ ํ–ˆ๋„ค์š”..

๋„ํ˜„๋‹˜์˜ ์ˆ˜๋„์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค ๐Ÿซ 

์ €๋Š” ๋ฐฑํŠธ๋ž˜ํ‚น์œผ๋กœ ๋ฌธ์ž์—ด ์กฐํ•ฉ์„ ์ฐพ์•„๊ฐ€๋ฉด์„œ,

๊ธธ์ด๊ฐ€ 4๋ฅผ ๋งŒ์กฑํ•˜๋ฉด์„œ, a, e, i, o, u๊ฐ€ ๋“ค์–ด ์žˆ๋Š” ๋ฌธ์ž์—ด๋“ค์„ ์ถœ๋ ฅํ•˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

// a c i s t w

int l,c;
char vowels[5] = {'a', 'e', 'i', 'o','u'};

void comb(string& s, string out, int idx, int len)
{

    char v_cnt =0;
    if (len == l)
    {
        for (char vowel : vowels)
        {
            if (out.find(vowel) != string::npos) v_cnt++;
        }
        if (l - v_cnt >= 2 && v_cnt >= 1)
            cout << out << '\n';
        return;
    }

    for (int i=idx;i<c;i++){
        comb(s, out +s[i], i+1, len+1);
    }

}

int main()
{
    cin >> l >> c;
    string s; char s_t;

    for (int i=0;i<c;i++)
    {
        cin >> s_t;
        s += s_t;
    }
    sort(s.begin(), s.end());

    comb(s, "", 0, 0);
}

@dohyeondol1
Copy link
Contributor

์ €๋„ ์œ ํ˜„๋‹˜์ฒ˜๋Ÿผ ๋ฐฑํŠธ๋ž˜ํ‚น์„ ์‚ฌ์šฉํ•˜์—ฌ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋Š” ์‚ด์ง ๋‹ค๋ฅด๋„ค์š”.
๋ชจ์Œ์€ ๊ฐ€๋” ๋ฌธ์ œ ํ’€ ๋•Œ ์˜๋‹จ์–ด๋ฅผ ์ฐพ์•„๋ด์„œ vowel ์ด๋ผ๋Š”๊ฑธ ์•Œ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ์ž์Œ์€ ์ด๋ฒˆ ๋ฌธ์ œ ํ’€๋ฉด์„œ ์ฒ˜์Œ ์•Œ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค..ใ…‹ใ…‹;;

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int L, C;
vector<char> chars;
vector<char> password;

void dfs(int start, int depth) {
    if(depth == L) {
        int vowel = 0, consonant = 0;
        for(char c : password) {
            if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') vowel++;
            else consonant++;
        }

        if(vowel >= 1 && consonant >= 2) {
            for(char c : password)
                cout << c;
            cout << '\n';
        }

        return;
    }

    for(int i = start; i < C; ++i) {
        password.push_back(chars[i]);
        dfs(i+1, depth+1);
        password.pop_back();
    }
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    cin >> L >> C;
    chars.resize(C);
    for(int i = 0; i < C; ++i)
        cin >> chars[i];

    sort(chars.begin(), chars.end());
    dfs(0, 0);

    return 0;
}

@froglike6 froglike6 changed the base branch from 19-froglike6 to main July 13, 2025 16:01
Copy link
Collaborator

@hadongun hadongun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combinations !!!

vowel_count = sum(1 for ch in comb if ch in vowels)
์ด๋Ÿฐ ์‹์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ƒ๋‹นํžˆ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์งค ์ˆ˜ ์žˆ๋‹ค๋Š”๊ฒŒ ํŒŒ์ด์ฌ์˜ ์žฅ์ ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
๋ชจ์Œ์„ ํ•˜๋‚˜ํ•˜๋‚˜ ๋ณด๋ฉด์„œ comb์— ์žˆ๋‹ค๋ฉด 1์„ ๋”ํ•˜๋Š” ์‹์œผ๋กœ ํ•˜๋‹ˆ ๋งค์šฐ ์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์ง€๋Š”๊ตฐ์šฉ

์—ด์‡  ์ฑ™๊ธฐ๊ธฐ

import sys
from itertools import combinations

input = sys.stdin.readline
L, C = map(int, input().split())
code = input().split()
code.sort()

vowels = {'a', 'e', 'i', 'o', 'u'}

for comb in combinations(code, L):
    vowel_count = sum(1 for ch in comb if ch in vowels)
    not_vowel_count = L - vowel_count

    if vowel_count >= 1 and not_vowel_count >= 2:
        print(''.join(comb))

@froglike6 froglike6 merged commit c5a5a97 into main Jul 16, 2025
1 check passed
@froglike6 froglike6 deleted the 20-froglike6 branch July 22, 2025 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants