백준 1759번 암호만들기를 풀어보겠습니다.
https://www.acmicpc.net/problem/1759
파이썬 코드
from itertools import combinations
L, C = map(int, input().split())
li = list(map(str, input().split()))
comb = list(combinations(li, L))
sorted_string = []
for tup in comb:
sorted_combs.append(sorted(tup))
for string in sorted(sorted_combs):
vowels = 0
consonants =0
for alphabet in string:
if alphabet in 'aeiou':
vowels += 1
else:
consonants += 1
if vowels >= 1 and consonants >= 2:
print("".join(string))
조건 & 구현
다음 조건을 만족하면서 구현하면 되는 문제이다.
가능한 알파벳 조합을 combinations 을 이용하여 나타내고
그 알파벳 조합을 다시 알파벳 순서대로 sorted 하여 다시 리스트에 넣어준다!
이 리스트를 모음과 자음 갯수를 만족하는 조합들만 print 해준다.