반응형
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
- 파이썬
- BFS
- BOJ
- 브루트포스
- MYSQL
- 구현
- 재귀
- DP
- 가상메모리
- N과M
- 백준
- 투포인터
- 수학
- 스택
- level1
- 가상메모리 관리
- dfs
- level2
- 에라스토테네스의 체
- 힙
- 다익스트라
- 그리디
- 코딩테스트
- 딕셔너리
- 다이나믹 프로그래밍
- 프로그래머스
- level3
- python
- programmers
- 운영체제
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 |