PS/Python
[Python] 백준 알고리즘 #1759 암호 만들기
yoo.o
2020. 8. 5. 01:41
반응형
문제
1759번: 암호 만들기
첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.
www.acmicpc.net
풀이
combinations을 사용해서 가능한 길이의 단어를 전부 다 구한 후, 조건에 맞는 애들만 프린트하는 방식으로 짰다.
모음이 최소 1개, 자음이 최소 2개이므로 모음은 최소 1개 ~ 최대 전체-2개
import sys
from itertools import combinations
L, C = map(int, sys.stdin.readline().split())
alphabets = sorted(list(map(str, sys.stdin.readline().split())))
vowels = ['a', 'e', 'i', 'o', 'u']
comb = combinations(alphabets, L)
for word in comb:
count = 0
for letter in word:
if letter in vowels:
count += 1
if 1 <= count <= L-2:
print(''.join(word))
반응형