

-Code
import java.io.*;
public class BOJ10604 {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int totalMin = 0;
while (true) {
String line = br.readLine();
if (line.equals("$$$") || line.equals("###")) {
System.out.println(String.format("%d:%02d", totalMin / 60, totalMin % 60));
// ###이면 탈출
if (line.equals("###")) {
break;
}
// $$$이면 다음 테스트 케이스를 위해 초기화
totalMin = 0;
continue;
}
// 부호와 분리
char calc = line.charAt(0);
line = line.substring(1);
// 정규 표현식으로 . 또는 :를 기준으로 나누기
String[] parts = line.split("[.:]");
// 시간 처리
int nowHour = parts[0].isEmpty() ? 0 : Integer.parseInt(parts[0]);
// 분 처리 (길이가 1이하인 경우 시간만 존재)
int nowMin = 0;
if (parts.length > 1) {
nowMin = parts[1].isEmpty() ? 0 : Integer.parseInt(parts[1]);
}
// 현재 시간을 분으로 환산해 부호에 따라 저장
int nowTotal = nowHour * 60 + nowMin;
totalMin += calc == '+' ? nowTotal : -nowTotal;
}
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [백준/Java] 27496번 발머의 피크 이론 (0) | 2026.03.29 |
|---|---|
| [프로그래머스/Java] [1차] 뉴스 클러스터링 (0) | 2026.03.28 |
| [프로그래머스/Java] 튜플 (0) | 2026.03.27 |
| [백준/Java] 33257번 상현이의 물리학및실험1 실험 대작전 (0) | 2026.03.27 |
| [프로그래머스/Java] 롤케이크 자르기 (0) | 2026.03.26 |