Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 딕셔너리
- MYSQL
- 재귀
- 백준
- level3
- 구현
- 가상메모리
- BFS
- BOJ
- 가상메모리 관리
- 프로그래머스
- 스택
- 수학
- 다익스트라
- programmers
- 그리디
- level1
- dfs
- N과M
- 파이썬
- 운영체제
- python
- 코딩테스트
- level2
- dict
- 다이나믹 프로그래밍
- DP
- 브루트포스
- 힙
- level0
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [방금그곡] 파이썬 본문
https://programmers.co.kr/learn/courses/30/lessons/17683
코딩테스트 연습 - [3차] 방금그곡
방금그곡 라디오를 자주 듣는 네오는 라디오에서 방금 나왔던 음악이 무슨 음악인지 궁금해질 때가 많다. 그럴 때 네오는 다음 포털의 '방금그곡' 서비스를 이용하곤 한다. 방금그곡에서는 TV,
programmers.co.kr
#프로그래머스 [3차] 방금그곡
m_={'C':'a','C#':'b','D':'c','D#':'d','E':'e','E#':'q','F':'f','F#':'g','G':'h','G#':'i','A':'j','A#':'k','B':'l'}
def mel_to_code(melody):
i=0
code=[]
while i<(len(melody)-1):
if melody[i+1]=='#':
code.append(m_[melody[i]+melody[i+1]])
i+=2
else:
code.append(m_[melody[i]])
i+=1
if not melody[-1]=='#':
code.append(m_[melody[-1]])
return code
def solution(m, musicinfos):
answer =[0,0]
m=''.join(mel_to_code(m))
for musicinfo in musicinfos:
start,end,title,melody=map(str,musicinfo.split(','))
melody=mel_to_code(melody)
melody_len=len(melody)
s_h,s_m=map(int,start.split(':'))
e_h,e_m=map(int,end.split(':'))
spend=(e_h-s_h)*60+(e_m-s_m)
if spend>melody_len:
for i in range(len(melody),spend):
melody.append(melody[i%melody_len])
elif spend<melody_len:
melody=melody[:spend]
melody=''.join(melody)
if m in melody:
if spend>answer[0]:
answer[1]=title
answer[0]=spend
if answer[1]==0:
return '(None)'
else:
return answer[1]
'#'처리를 하는게 중요한 문제인것같다.
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [뉴스 클러스터링] 파이썬 (0) | 2021.12.18 |
---|---|
프로그래머스 level2 [괄호 변환] 파이썬 (0) | 2021.12.18 |
프로그래머스 level2 [튜플] 파이썬 (0) | 2021.12.17 |
프로그래머스 level2 [전화번호 목록] 파이썬 (0) | 2021.12.11 |
프로그래머스 level2 [더 맵게] 파이썬 (0) | 2021.12.11 |