
-Code
class Solution {
public String solution(
String video_len, String pos, String op_start,
String op_end, String[] commands
) {
// 현재 시간을 초로 변경
String[] posStr = pos.split(":");
int nowSec = Integer.parseInt(posStr[0]) * 60 + Integer.parseInt(posStr[1]);
// 비디오 끝나는 시간 초로 변경
String[] totalTimeStr = video_len.split(":");
int totalTime = Integer.parseInt(totalTimeStr[0]) * 60 + Integer.parseInt(totalTimeStr[1]);
// 오프닝 시작을 초로 변경
String[] opStartStr = op_start.split(":");
int opStart = Integer.parseInt(opStartStr[0]) * 60 + Integer.parseInt(opStartStr[1]);
// 오프닝 끝나느 시간을 초로 변경
String[] opEnddStr = op_end.split(":");
int opEnd = Integer.parseInt(opEnddStr[0]) * 60 + Integer.parseInt(opEnddStr[1]);
// 커맨드에 따른 시간 변화
for (String comm : commands) {
// 오프닝 위치면 끝나는 위치로 변경
if (nowSec >= opStart && nowSec <= opEnd) {
nowSec = opEnd;
}
// next면 10초 더하고 아니면 -10
nowSec += comm.equals("next") ? 10 : -10;
nowSec = Math.max(0, Math.min(totalTime, nowSec));
}
// 결과에 한번더 오프닝 위치 확인
if (nowSec >= opStart && nowSec <= opEnd) {
nowSec = opEnd;
}
return String.format("%02d:%02d", nowSec / 60, nowSec % 60);
}
}
변수를 잘못입력과 오프닝 검사를 커맨드 검사 이후 한 번 더 안 했어서 틀렸었습니다.
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [프로그래머스/Java] 가장 많이 받은 선물 (0) | 2026.03.24 |
|---|---|
| [백준/Java] 10655번 마라톤 1 (0) | 2026.03.24 |
| [프로그래머스/Java] 유연근무제 (0) | 2026.03.23 |
| [백준/Java] 12021번 보물 찾기 (0) | 2026.03.23 |
| [프로그래머스/Java] 중요한 단어를 스포 방지 (0) | 2026.03.22 |