[백준] 1759번 암호 만들기

게으른 완벽주의자·2023년 1월 23일

백준

목록 보기
2/27

백준_1759

L과 C의 범위가 최대 15이기 때문에 combinations 사용 가능
모음과 자음 리스트를 따로 나눠주고 그 중에 최소 1개의 모음, 최소 2개 이상의 자음을 가지는 조합을 찾아내고 알파벳 순으로 정리한다
중복조합이 아니기 때문에 나온 결과 answer이 이미 result 안에 있을 일은 없다

from itertools import combinations

#최소 1개의 모음, 최소 2개 이상의 자음
l, c = map(int, input().split())
data = list(input().split())
mo = [i for i in data if i in ['a', 'e', 'i', 'o', 'u']]
ja = [i for i in data if i not in mo]

result = []
for i in range(1,l-1):
    for mo_list in combinations(mo, i):
        for ja_list in combinations(ja, l-i):
            answer = list(mo_list+ja_list)
            answer = ''.join(sorted(answer))
            result.append(answer)

result.sort()
for r in result:
    print(r)
profile
데이터를 공부하고 있습니다

0개의 댓글