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
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 1475 방 번호 (0) | 2023.03.20 |
|---|---|
| [파이썬] 백준 1107 리모컨 (0) | 2023.03.20 |
| [파이썬] 백준 7576 토마토 (0) | 2023.03.13 |
| [파이썬] 백준 23561 Young한 에너지는 부족하다 (0) | 2023.03.13 |
| [파이썬] 백준 1697 숨바꼭질 (0) | 2023.02.22 |