[백준] 1759번 (python 파이썬) 암호만들기
2021. 3. 27. 20:59ㆍ발돋움/알고리즘
728x90
반응형

주의할 점은 암호에 모음 1개 & 자음 2개 이상이어야하며 암호는 오름차순이어야 한다.
def moja(password):
mo = 0
ja = 0
for x in password:
if x in 'aeiou':
mo += 1
else:
ja += 1
return mo >= 1 and ja >= 2
def solve(idx, l, password, word):
if len(password) == l:
if moja(password):
print(password)
return
if idx == len(word):
return
solve(idx + 1, l, password + word[idx], word)
solve(idx + 1, l, password, word)
L, C = map(int, input().split())
word = sorted(input().split())
solve(0, L, '', word)
728x90

재귀는 너무 힘들다.
728x90
반응형
'발돋움 > 알고리즘' 카테고리의 다른 글
| [백준] 14501번(python 파이썬) 퇴사 (0) | 2021.03.30 |
|---|---|
| [백준] 1248번(python 파이썬) 맞춰봐 (0) | 2021.03.28 |
| [백준] 15652번 (python 파이썬) N과 M(4) (0) | 2021.03.27 |
| [백준] 15649번 (python 파이썬) N과 M(1) (0) | 2021.03.27 |
| [백준] 9095번 (python 파이썬) 1,2,3 더하기 (0) | 2021.03.26 |