[Programmers/Python] [PCCP 기출문제] 1번 / 동영상 재생기

도니·2024년 11월 15일

Interview-Prep

목록 보기
1/29
post-thumbnail

문제

[프로그래머스] [PCCP 기출문제] 1번 / 동영상 재생기

풀이

코드

def solution(video_len, pos, op_start, op_end, commands):
    answer = ''
    
    end_mm, end_ss = map(int, video_len.split(":"))
    end_time = end_mm*60 + end_ss
    
    pos_mm, pos_ss = map(int, pos.split(":"))
    pos_time = pos_mm*60 + pos_ss
    
    op_start_mm, op_start_ss = map(int, op_start.split(":"))
    op_start_time = op_start_mm*60 + op_start_ss
    
    op_end_mm, op_end_ss = map(int, op_end.split(":"))
    op_end_time = op_end_mm*60 + op_end_ss
    
    print(f"end_time: {op_end_time}")
    print(f"pos_time: {pos_time}")
    print(f"op_start_time: {op_start_time}")
    print(f"op_end_time: {op_end_time}")
    
    if pos_time >= op_start_time and pos_time <= op_end_time:
        pos_time = op_end_time
    
    for c in commands:
        if c == "prev":
            pos_time = max(0, pos_time-10)
        if c == "next":
            pos_time = min(end_time, pos_time+10)

        if pos_time >= op_start_time and pos_time <= op_end_time:
            pos_time = op_end_time
    
    ans_mm = int(pos_time / 60)
    ans_ss = pos_time % 60
    answer = str(ans_mm).zfill(2)+":"+str(ans_ss).zfill(2)
    
    return answer
profile
Where there's a will, there's a way

0개의 댓글