반응형
https://www.acmicpc.net/problem/1759
import itertools
r, n = map(int, input().split())
letters = list(input().split())
consonants = []
vowels = []
for i in range(n):
if letters[i] in "aeiou":
vowels.append(letters[i])
else:
consonants.append(letters[i])
words = []
for i in range(1, min(r-1,len(vowels)+1)):
# i is number of vowels in word
vow = list(itertools.combinations(vowels, i))
conso = list(itertools.combinations(consonants, r-i))
for j in range(len(vow)):
for k in range(len(conso)):
p = list(vow[j]+conso[k])
a = ''.join(sorted(p))
words.append(a)
words.sort()
for i in range(len(words)):
print(words[i])
시키는 거 잘 하면 되는 문제다.
댓글