Algorithm/Programmers
[프로그래머스] [PCCP 기출문제] 1번 / 동영상 재생기 - Python
Dev.sohee
2024. 10. 13. 22:30
https://school.programmers.co.kr/learn/courses/30/lessons/340213
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
초 단위로 시간 변환 후 prev, next 처리
def to_sec(time):
tmp = time.split(":")
return int(tmp[0]) * 60 + int(tmp[1])
def solution(video_len, pos, op_start, op_end, commands):
answer = ''
video_len = to_sec(video_len)
pos = to_sec(pos)
op_start = to_sec(op_start)
op_end = to_sec(op_end)
for cmd in commands:
if op_start <= pos <= op_end:
pos = op_end
if cmd == "next":
pos += 10
else:
pos -= 10
if pos < 0 :
pos = 0
elif pos > video_len:
pos = video_len
if op_start <= pos <= op_end:
pos = op_end
minutes = str(pos // 60).zfill(2)
seconds = str(pos % 60).zfill(2)
answer = minutes + ":" + seconds
return answer