[백준] 1759: 암호 만들기

hyunhee·2022년 7월 7일
0

algorithm

목록 보기
16/20

첫 골드 문제

풀이

암호가 알파벳 순으로 정해져 있고 중복되는 것이 없기 때문에 조합을 이용한다. itertools 라이브러리에서 combinations 함수를 import한다.
입력받은 문자열 리스트를 오름차순 정렬한다. 조합한 모든 암호를 array 리스트에 저장한다. array에 있는 단어에서 모음의 개수를 세고 모음의 개수가 0이거나 자음의 개수가 2개 미만이면 출력하지 않는다. 나머지는 출력한다.

import sys
from itertools import combinations 

def input():
    return sys.stdin.readline().rstrip()

l, c = map(int, input().split())
alphabet = list(input().split())
alphabet.sort()

array = list(combinations(alphabet, l))

for i in array:
    cnt = 0
    for j in i:
        if j in 'aeiou':
            cnt += 1
    if cnt == 0 or l - cnt < 2:
        continue

    print(''.join(i))

0개의 댓글