내 풀이
def solution(video_len, pos, op_start, op_end, commands):
answer = ''
# 시간 str을 모두 초단위로 변환하여 계산하는 함수
def time_to_sec(*time_string):
sec_list = []
for _t in time_string:
mm, ss = map(int, _t.split(":"))
ss += mm * 60
sec_list.append(ss)
return sec_list
# 최종적으로 계산된 초를 시간 단위로 변환하는 함수
def sec_to_time(second):
mm = str(second // 60).rjust(2, '0')
ss = str(second % 60).rjust(2, '0')
return f"{mm}:{ss}"
# 모든 시간 str을 초단위로 변환 후 사용
video_len, pos, op_start, op_end = time_to_sec(video_len, pos, op_start, op_end)
for command in commands:
if op_start <= pos < op_end: # 이동 전후로 오프닝 생략
pos = op_end
if command == "next": # 가장 끝 위치를 넘어가지 않도록 조정
pos = min(pos+10, video_len)
elif command == "prev": # 가장 첫 위치를 넘어가지 않도록 조정
pos = max(pos-10, 0)
if op_start <= pos < op_end: # 이동 전후로 오프닝 생략
pos = op_end
answer = sec_to_time(pos)
return answer
메모
길이만큼 문자 채우기 : str.rjust(채울 개수, 채울 문자)
길이만큼 0 채우기 : str.zfill(채울 개수)
'PROGRAMMERS' 카테고리의 다른 글
[프로그래머스/파이썬] 튜플 (0) | 2025.01.14 |
---|---|
[프로그래머스/파이썬] [1차] 캐시 (0) | 2025.01.13 |
[프로그래머스/파이썬] [PCCE 기출문제] 10번 / 공원 (13) | 2025.01.09 |
[프로그래머스/파이썬] [PCCE 기출문제] 9번 / 지폐 접기 (2) | 2025.01.07 |
[프로그래머스/파이썬] [1차] 뉴스 클러스터링 (2) | 2025.01.04 |