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 |
Tags
- level1
- 다익스트라
- 힙
- 백준
- level0
- 구현
- dfs
- 코딩테스트
- BOJ
- 재귀
- 브루트포스
- 파이썬
- level3
- programmers
- python
- 수학
- 가상메모리 관리
- dict
- BFS
- 운영체제
- 가상메모리
- 프로그래머스
- N과M
- level2
- DP
- 다이나믹 프로그래밍
- 딕셔너리
- 그리디
- 스택
- MYSQL
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [방금그곡] 파이썬 본문
https://programmers.co.kr/learn/courses/30/lessons/17683
#프로그래머스 [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 |