title: "[프로그래머스] [3차] 방금그곡 Python 파이썬 해설 (Level 2) - 이도훈"
cleanUrl: "programmers/17683"
description: "프로그래머스 Level 2 문제 [[3차] 방금그곡]의 풀이를 정리합니다."
def h2m(s):
return 60*int(s.split(':')[0]) + int(s.split(':')[1])
def parse(musicinfo):
start, end, name, melody = musicinfo.split(',')
duration = h2m(end) - h2m(start)
melody = melody.replace('C#', 'H').replace('D#', 'I').replace('F#', 'J').replace('G#', 'K').replace('A#', 'L')
full_melody = melody * (duration // len(melody) + 1)
full_melody = full_melody[:duration]
return name, duration, full_melody
def solution(m, musicinfos):
m = m.replace('C#', 'H').replace('D#', 'I').replace('F#', 'J').replace('G#', 'K').replace('A#', 'L')
max_duration, answer = -1, '(None)'
for name, duration, melody in [parse(x) for x in musicinfos]:
if m in melody and duration > max_duration:
answer = name
max_duration = duration
return answer
프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges