※ 340213 동영상 재생기
https://school.programmers.co.kr/learn/courses/30/lessons/340213
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
문제 해결 TIP
모든 시간이 "00:00" 형태로 되어 있어 분과 초를 따로 계산하기 번거롭다. 시간을 모두 초로 변환하여 계산해준다.
전체 코드
def change_to_sec(time):
minutes, seconds = time.split(':')
time = int(minutes)*60 + int(seconds)
return time
def solution(video_len, pos, op_start, op_end, commands):
answer = ''
#시간을 초로 변환
video_len = change_to_sec(video_len)
pos = change_to_sec(pos)
op_start = change_to_sec(op_start)
op_end = change_to_sec(op_end)
for i in range(len(commands)):
#오프닝 체크
if op_start <= pos <= op_end:
pos = op_end
if commands[i]=='prev':
if pos < 10:
pos = 0
else:
pos = pos - 10
elif commands[i]=='next':
if (video_len-pos)<10:
pos = video_len
else:
pos = pos + 10
#오프닝 한번 더 체크
if op_start <= pos <= op_end:
pos = op_end
#초를 제시한 시간 형태로 변환하여 출력
answer = str(f"{pos//60:02}")+':'+str(f"{pos%60:02}")
return answer
'Python > 구현' 카테고리의 다른 글
[Algorithm] 구현 (1) | 2024.01.05 |
---|
댓글