[백준 - 1759] 암호 만들기

koyo·2020년 9월 24일
0

백준

목록 보기
2/13
post-thumbnail

문제

문제링크
주어진 알파벳과 암호 길이를 바탕으로 만든다. 암호의 조건은 자음의 숫자가 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))
profile
클라우드 개발자가 될 코요입니다.

0개의 댓글