문제링크
주어진 알파벳과 암호 길이를 바탕으로 만든다. 암호의 조건은 자음의 숫자가 2개 이상, 모음의 숫자가 1개 이상이다. 가능성 있는 암호들을 모두 구하시오.
itertools의 combinations(조합)을 활용하자!
모든 조합의 수를 구해두고, 조건에 맞는 것만 출력하면 된다.
from itertools import combinations
vowels = ('a', 'e', 'i', 'o', 'u') # 5개의 모음 정의
l, c = map(int, input().split())
array = sorted(list(input().split()))
for password in combinations(array, l):
# 패스워드에 포함된 각 문자를 확인하며 모음의 개수를 세기
count = 0
for i in password:
if i in vowels:
count += 1
# 최소 1개의 모음과 최소 2개의 자음이 있는 경우 출력
if count >=1 and count <= l - 2:
print(''.join(password))