728x90
반응형
import java.util.*;
class Solution {
static int pM, pS;
public String solution(String video_len, String pos, String op_start, String op_end, String[] commands) {
String answer = "";
int vM, vS, osM, osS, oeM, oeS;
String []tmp = video_len.split(":");
vM = Integer.parseInt(tmp[0]);
vS = Integer.parseInt(tmp[1]);
tmp = pos.split(":");
pM = Integer.parseInt(tmp[0]);
pS = Integer.parseInt(tmp[1]);
tmp = op_start.split(":");
osM = Integer.parseInt(tmp[0]);
osS = Integer.parseInt(tmp[1]);
tmp = op_end.split(":");
oeM = Integer.parseInt(tmp[0]);
oeS = Integer.parseInt(tmp[1]);
opening(osM, osS, oeM, oeS);
for(int i=0; i<commands.length; i++) {
opening(osM, osS, oeM, oeS);
if(commands[i].equals("prev")) {
prev();
}
else if(commands[i].equals("next")) {
next(vM, vS);
}
opening(osM, osS, oeM, oeS);
}
if(pM < 10) answer += "0" + pM;
else answer += pM;
answer += ":";
if(pS <10) answer += "0" + pS;
else answer += pS;
return answer;
}
public void prev() {
if(pS - 10 >= 0) {
pS = pS - 10;
} else {
if(pM - 1 < 0) {
pM = 0;
pS = 0;
} else {
pM = pM - 1;
pS = pS + 60 - 10;
}
}
}
public void next(int vM, int vS) {
if(pS + 10 >= 60) {
if(pM + 1 > vM) {
pM = vM;
pS = vS;
}
else if(pM + 1 == vM && pS + 10 - 60 >= vS) {
pM = vM;
pS = vS;
}
else {
pM = pM + 1;
pS = pS + 10 - 60;
}
} else {
if(pM >= vM && pS + 10 > vS) {
pS = vS;
pM = vM;
}
else pS = pS + 10;
}
}
public void opening(int osM, int osS, int oeM, int oeS) {
if(pM > osM && pM < oeM) {
pM = oeM;
pS = oeS;
}
else if(pM == osM && pS>= osS && pS<=59 && pM < oeM) {
pM = oeM;
pS = oeS;
}
else if(pM == osM && pM == oeM && (pS >= osS && pS <= oeS)) {
pM = oeM;
pS = oeS;
}
else if(pM == oeM && pS <= oeS && pM > osM) {
pM = oeM;
pS = oeS;
}
}
}
728x90
반응형
'Coding Test > Programmers' 카테고리의 다른 글
[JAVA][Programmers] 정렬 - K번째수 (0) | 2025.02.04 |
---|---|
[JAVA][Programmers] 정렬 - 가장 큰 수 (0) | 2025.02.04 |
[JAVA][Programmers][PCCP 기출문제] 2번 / 퍼즐 게임 챌린지 (0) | 2025.02.04 |
[JAVA][Programmers] 해시 - 폰켓몬 (2) | 2025.02.04 |
[JAVA][Programmers] 해시 - 완주하지 못한 선수 (0) | 2025.02.04 |