ALGORITHM STUDY WITH PYTHON/BFS | DFS
boj.kr/1759 암호 만들기 (gold5) 파이썬 풀이
ebson
2023. 4. 23. 17:49
1. 입력받은 후보 문자들 중 모음문자를 vowels에 저장
2. combinations를 사용해 추출한 모든 L개의 문자 조합에 대해 아래를 반복
2.1. 모음문자의 개수를 카운트
2.2. 모음문자가 0개보다 많고 L-2개 이하이면, passwords 배열에 append
3. passwords 배열을 정렬한 후 순회하면서 출력
L, C = map(int, input().split())
words = list(input().split())
vowels = []
for w in words:
if w in ('a', 'e', 'i', 'o', 'u'):
vowels.append(w)
passwords = []
from itertools import combinations
for combi in combinations(words, L):
v_cnt = 0
for c in combi:
if c in vowels:
v_cnt += 1
if 0 < v_cnt <= L-2:
passwords.append(''.join(sorted(list(combi))))
for password in sorted(passwords):
print(password)
itertools에서 combinations를 import 하고 배열로부터 N개의 요소를 추출하는 모든 조합을 구할 수 있다.