๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ๐Ÿฃ: ๐’œ๐“๐‘”๐‘œ๐“‡๐’พ๐“‰๐’ฝ๐“‚/์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ’€์ด

BOJ1759: ์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ(Gold 5)

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>

using namespace std;
bool checkfun(char *a, int L);
void permu(char *a, char *target, int start, int level, int L, int C);
bool compare(char a, char b)
{
    return int(a) < int(b);
}

int main()
{
    int L, C;
    char alphabet[30] = {
        0,
    };
    cin >> L >> C;
    for (int i = 0; i < C; i++)
        cin >> alphabet[i];

    sort(alphabet, alphabet + C, compare);
    char result[30] = {
        ""};
    //for (int i = 0; i <= C - L; i++)
    permu(alphabet, result, 0, 0, L, C);
}

bool checkfun(char *a, int L) //์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์ด ์•”ํ˜ธ์ผ ์ˆ˜ ์žˆ๋Š”๊ฐ€
{
    int cnt_v = 0; //๋ชจ์Œ๊ฐœ์ˆ˜
    int cnt_c = 0; //์ž์Œ๊ฐœ์ˆ˜
    for (int i = 0; i < L; i++)
    {
        if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u')
            cnt_v++;
        else
            cnt_c++;
    }
    if (cnt_v >= 1 &&cnt_c >= 2)
        return true;
    else
        return false;
}

void permu(char *a, char *target, int start, int level, int L, int C)
{
    if (level == L)
    {
        if (checkfun(target, L))
            cout << target << "\n";
        return;
    }
    for (int i = start; i < C - L + level + 1; i++)
    {
        target[level] = a[i];
        // printf("ํ˜„์žฌ ๋ฌธ์ž : %c start : %d level : %d \n", target[level], start, level);
        permu(a, target, i + 1, level + 1, L, C);
    }
}