Programmers / 모음 사전 / Python 파이썬

2022. 5. 26. 20:42·coding test - python/Programmers
728x90
반응형

 

*문제 출처는 프로그래머스에 있습니다.

문제 제목: 모음 사전 (2단계)

문제 사이트: https://programmers.co.kr/learn/courses/30/lessons/84512

 


나의 풀이

from itertools import product

def solution(word):
    words = []
    for i in range(1, 6):
        for c in product(['A', 'E', 'I', 'O', 'U'], repeat=i):
            words.append(''.join(list(c)))
    words.sort()
    return words.index(word) + 1

처음에는 복잡하게 생각해서 sort를 안하고 문제를 풀었었다... 그래서 문제를 빙 돌아가면서 풀었는데 이게 맞았다!

 

위: sort로 정렬 전/ 아래: sort로 정렬 후

다른답안 (규칙 이용)

등비수열의 합을 이용한 풀이다.

def solution(word):
    answer = 0
    for i, n in enumerate(word):
        answer += (5 ** (5 - i) - 1) / (5 - 1) * "AEIOU".index(n) + 1
    return answer

※ 알아야 할 것

- product , 중복 순열을 이용해서 가능한 모든 조합을 만들고 sort함수로 정렬해줌

 

728x90
반응형

'coding test - python > Programmers' 카테고리의 다른 글

Programmers / 다음 큰 숫자 / Python 파이썬  (0) 2022.06.27
Programmers / 줄 서는 방법 / Python 파이썬  (0) 2022.06.26
Programmers / 짝지어 제거하기 / Python 파이썬  (0) 2022.05.25
Programmers / 구명보트 / Python 파이썬  (0) 2022.05.25
Programmers / 프린터 / Python 파이썬 - 작성중  (0) 2022.05.20
'coding test - python/Programmers' 카테고리의 다른 글
  • Programmers / 다음 큰 숫자 / Python 파이썬
  • Programmers / 줄 서는 방법 / Python 파이썬
  • Programmers / 짝지어 제거하기 / Python 파이썬
  • Programmers / 구명보트 / Python 파이썬
sillon
sillon
꾸준해지려고 합니다..
    반응형
  • sillon
    sillon coding
    sillon
  • 전체
    오늘
    어제
    • menu (612)
      • notice (2)
      • python (68)
        • 자료구조 & 알고리즘 (23)
        • 라이브러리 (19)
        • 기초 (8)
        • 자동화 (14)
        • 보안 (1)
      • coding test - python (301)
        • Programmers (166)
        • 백준 (76)
        • Code Tree (22)
        • 기본기 문제 (37)
      • coding test - C++ (5)
        • Programmers (4)
        • 백준 (1)
        • 기본기문제 (0)
      • 공부정리 (138)
        • 신호처리 시스템 (0)
        • Deep learnig & Machine lear.. (41)
        • Data Science (18)
        • Computer Vision (17)
        • NLP (40)
        • Dacon (2)
        • 모두를 위한 딥러닝 (강의 정리) (4)
        • 모두의 딥러닝 (교재 정리) (9)
        • 통계 (2)
      • HCI (22)
        • Haptics (7)
        • Graphics (11)
        • Arduino (3)
      • Project (20)
        • Web Project (0)
        • App Project (1)
        • Paper Project (1)
        • 캡스톤디자인2 (17)
        • etc (1)
      • OS (10)
        • Ubuntu (9)
        • Rasberry pi (1)
      • App & Web (9)
        • Android (7)
        • javascript (2)
      • C++ (5)
        • 기초 (5)
      • Cloud & SERVER (7)
        • Git (2)
        • Docker (0)
        • DB (4)
      • Paper (7)
        • NLP Paper review (6)
      • 데이터 분석 (0)
        • GIS (0)
      • daily (2)
        • 대학원 준비 (0)
      • 영어공부 (6)
        • job interview (2)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Python
    programmers
    소수
    백준
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
sillon
Programmers / 모음 사전 / Python 파이썬
상단으로

티스토리툴바