[백준 완전탐색] 암호 만들기(python)

이진규·2022년 8월 21일
1

백준(PYTHON)

목록 보기
78/115

문제

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

나의 코드

"""

"""

from itertools import combinations
from sys import stdin
input = stdin.readline

l, c = map(int, input().split())
lst = list(input().split())
lst.sort() # 문제에서 알파벳이 암호에서 증가하는 순으로 배치한다고 언급

answer = list(combinations(lst, l)) # 조합 이용
remove_index = []

for i in range(len(answer)): # 만약 자음이 2개 미만이거나 모음이 1개 미만인경우 삭제한다.
    consonant, vowel = 0, 0
    for j in answer[i]:
        if j in ('a', 'e', 'i', 'o', 'u'):
            vowel += 1
        else:
            consonant += 1

    if consonant < 2 or vowel < 1:
        remove_index.append(i)

for i in range(len(answer)): # 자음 2개미만, 모음 1개미만이 아닌 경우에만 공백을 join으로 삭제하면서 출력한다.
    if i not in remove_index:
        print(''.join(answer[i]))

    

설명

골드5 문제이지만 문제 설명 그대로 구현하면 쉬운 문제

참고 자료

profile
항상 궁금해하고 공부하고 기록하자.

0개의 댓글