728x90

생각보다 시간 초과 없이 잘 풀렸다. 조합을 이용해 알맞은 경우를 count 해주었다.

from itertools import combinations
 
def find(n):
 
    n = list(n)
 
    check = ['a','e','i','o','u']
 
    mo = 0
    ja = 0
 
    for i in range(0,len(n)):
        if n[i] in check:
            mo+=1
        else:
            ja+=1
 
    if mo>=1 and ja>=2:
        return True
 
a, b = map(int,input().split(" "))
 
k = list(input().split(" "))
 
answer = [ ]
 
# 최소 한 개의 모음(a, e, i, o, u)과 최소 두 개의 자음
 
 
 
 
w = list(combinations(k,a))
 
for j in range(0,len(w)):
    if find("".join(w[j])) == True:
        answer.append("".join(sorted("".join(w[j]))))
answer =sorted(answer)        
for i in answer:
    print(i)
 
 
 
 
 
 
 
728x90

+ Recent posts