[알고리즘/백준] 1759번 : 암호 만들기(python)

유현민·2022년 3월 28일
0

알고리즘

목록 보기
78/253

완전 노가다로 풀었다. 자음 모음을 분리해서 combinations를 갯수별로 해주고 그걸 합쳐서 해결함.

from itertools import combinations


def pw():
    global res

    for i in range(1, len(vow) + 1):
        if L - i == 1:
            break
        for v in combinations(vow, i):
            for c in combinations(cons, L - i):
                ans = list(v)
                ans.extend(list(c))
                res.append(''.join(sorted(ans)))
    return


if __name__ == "__main__":
    L, C = map(int, input().split())
    cons = list()  # 자음
    vow = list()  # 모음
    res = list()
    for i in input().split():
        if i in ['a', 'e', 'i', 'o', 'u']:
            vow.append(i)
        else:
            cons.append(i)
    pw()
    for i in (sorted(res)):
        print(i)
profile
smilegate megaport infra

0개의 댓글