동캄의 코딩도장

백준 1759 [암호만들기] 파이썬 본문

코테/BOJ

백준 1759 [암호만들기] 파이썬

동 캄 2022. 2. 9. 12:45

https://www.acmicpc.net/problem/1759

 

1759번: 암호 만들기

첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.

www.acmicpc.net

import sys
import itertools
input = sys.stdin.readline
L, C = map(int, input().split())
lst = list(map(str, input().split()))
lst.sort()

combi = itertools.combinations(lst, L)

for p in combi:
    count = 0
    count = (p.count('a')+p.count('e')+p.count('i')+p.count('o')+p.count('u'))
    if count >= 1 and count <= L-2:
        print(''.join(p))

permutation을 하면서 모음의 개수와 자음의 개수를 센다.