조합 - 암호 만들기

jiholee·2021년 12월 21일
0

코딩테스트 - python

목록 보기
8/10

하나의 리스트에서 모든 조합을 구할 때 combinations를 쓰면 편하다.

1759 암호 만들기

from itertools import combinations

L, C = map(int, input().split())
chars = sorted(list(input().split()))

vowels = set(['a', 'e', 'i', 'o', 'u'])


for password in list(combinations(chars, L)):   # L길이로 가능한 모든 비번 조합 에서 하나씩
    v_cnt = c_cnt = 0
    for ps in password:
        if ps in vowels:  # 모음 개수 세기
            v_cnt += 1
        else:
            c_cnt += 1  # 자음 개수 세기
    if v_cnt >= 1 and c_cnt >= 2:
        print("".join(password))

0개의 댓글