July 27, 2021
문제를 제대로 안 읽어서 헤맸다.
아래 조건을 빼먹었다.
reverse = True
를 빼먹었다.from datetime import datetime
def solution(m, musicinfos):
dic = dict()
m = process(m)
answer = []
for music in musicinfos:
start, end, title, melody = music.split(',')
temp = str(datetime.strptime(end, '%H:%M') - datetime.strptime(start, '%H:%M'))
minute = int(temp[-5:-3])
hour = int(temp[:-6])
duration = minute + hour * 60
melody = process(melody)
if duration < len(melody):
dic[title] = (melody[:duration], duration)
else:
q, r = divmod(duration, len(melody))
dic[title] = (melody * q + melody[:r], duration)
for key, value in dic.items():
if m in value[0]:
answer.append([key, value[1]])
print(answer)
try:
answer = sorted(answer, key=lambda x: x[1], reverse=True)
return answer[0][0]
except:
return '(None)'
def process(m):
return m.replace('C#', 'c').replace('D#', 'd').replace('F#', 'f').replace('G#', 'g').replace('A#', 'a')