문제
https://school.programmers.co.kr/learn/courses/30/lessons/340213
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
문제풀이
class Solution {
public String solution(String video_len, String pos, String op_start, String op_end, String[] commands) {
int videotime = covsec(video_len);
int postime = covsec(pos);
int opstime = covsec(op_start);
int opetime = covsec(op_end);
for(String com : commands){
postime = (opstime <= postime && opetime >= postime) ? opetime : postime;
if(com.equals("prev"))
postime = postime-10 < 0 ? 0 : postime - 10;
else
postime = videotime < postime + 10 ? videotime : postime + 10;
}
postime = (opstime <= postime && opetime >= postime) ? opetime : postime;
return ((postime / 60 < 10) ? "0" + postime / 60 : postime / 60) + ":" + ((postime % 60 < 10) ? "0" + postime % 60 : postime % 60 +"");
}
public int covsec(String time){
int min = Integer.parseInt(time.substring(0,2));
int sec = Integer.parseInt(time.substring(3,5));
return min*60+sec;
}
}