• 문제 링크
https://www.acmicpc.net/problem/1408
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Time t = new Time(br.readLine());
int n = calc(new Time(br.readLine())) - calc(t);
if (n < 0) n += 86400;
bw.write(String.format("%02d:%02d:%02d", n / 3600, n % 3600 / 60, n % 60));
bw.flush();
}
private static int calc(Time t) {
return t.h * 3600 + t.m * 60 + t.s;
}
private static class Time {
int h, m, s;
Time(String s) {
StringTokenizer st = new StringTokenizer(s, ":");
this.h = Integer.parseInt(st.nextToken());
this.m = Integer.parseInt(st.nextToken());
this.s = Integer.parseInt(st.nextToken());
}
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 32979 아파트 - Data Structure / Java (0) | 2025.01.18 |
---|---|
[백준] 32953 회상 - Data Structure / Java (0) | 2025.01.17 |
[백준] 10988 팰린드롬인지 확인하기 - Implementation / Java (0) | 2025.01.15 |
[백준] 1284 집 주소 - Implementation / Java (0) | 2025.01.14 |
[백준] 1652 누울 자리를 찾아라 - Implementation / Java (0) | 2025.01.13 |
댓글