ps | |
---|---|
링크 | programmers.co.kr/… |
출처 | 프로그래머스 |
문제 번호 | 84512 |
문제명 | 모음 사전 |
레벨 | Level 2 |
분류 |
애드혹 |
시간복잡도 | O(n) |
인풋사이즈 | n<=5 |
사용한 언어 | Python |
해결날짜 | 2021/08/30 |
def solution(word):
return sum(1 + 'AEIOU'.index(ch) * (5**(5 - i) - 1) // 4 for i, ch in enumerate(word))
"""Solution code for "Programmers 84512. 모음 사전".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/84512
- Solution link: http://www.teferi.net/ps/problems/programmers/84512
"""
import bisect
import itertools
def solution(word):
dic = []
for i in range(1, 6):
dic.extend(itertools.product('AEIOU', repeat=i))
return bisect.bisect(sorted(dic), tuple(word))
"""Solution code for "Programmers 84512. 모음 사전".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/84512
- Solution link: http://www.teferi.net/ps/problems/programmers/84512
"""
def solution(word):
v = 0
count = [v := v + 5**i for i in range(5)]
pos = sum(1 + 'AEIOU'.index(ch) * c for ch, c in zip(word, reversed(count)))
return pos