프로그래머스/LV1
[프로그래머스 Lv1, python] - [PCCP 기출문제] 1번 / 동영상 재생기
chyam_eun
2025. 5. 20. 15:21

https://school.programmers.co.kr/learn/courses/30/lessons/340213
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
def change(num): # 초단위로 바꿔주기. 변수를 m,s로 둬야하는데 h,m으로 해버림,,
res = 0
h,m = num.split(":")
res += int(h)*60 + int(m)
return res
def res(num,ans): # 마지막에 "mm:ss"로 바꿔주기.
if num<10:
ans+='0'+str(num)
else:
ans+=str(num)
return ans
def solution(video_len, pos, op_start, op_end, commands):
answer = ''
video_len, pos, op_start, op_end = change(video_len),change(pos),change(op_start),change(op_end)
for cm in commands:
if op_start <= pos < op_end: # 현재 상태가 오프닝 구간이면 건너뛰기
pos = op_end
if cm == "prev": # 이전으로 가기
pos = max(0, pos-10)
else: # 다음으로 가기
pos = min(video_len, pos+10)
if op_start <= pos < op_end: # 현재 상태가 오프닝 구간이면 건너뛰기
pos = op_end
h, m = pos//60, pos%60
# 각각 10보다 작으면 앞에 0붙이기
ans = res(h,answer)
ans += ":"
ans = res(m,ans)
return ans