https://www.acmicpc.net/problem/13223
13223번: 소금 폭탄
첫째 줄에는 현재 시각이 hh:mm:ss로 주어진다. 시간의 경우 0≤h≤23 이며, 분과 초는 각각 0≤m≤59, 0≤s≤59 이다. 두 번째 줄에는 소금 투하의 시간이 hh:mm:ss로 주어진다.
www.acmicpc.net
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str1 = br.readLine().split(":");
int second1 = Integer.valueOf(str1[0])*60*60+Integer.valueOf(str1[1])*60+Integer.valueOf(str1[2]);
String[] str2 = br.readLine().split(":");
int second2 = Integer.valueOf(str2[0])*60*60+Integer.valueOf(str2[1])*60+Integer.valueOf(str2[2]);
int ans = second2-second1;
if(ans<=0){
ans+= 24*60*60;
}
int hours = ans / (60 * 60);
int minutes = (ans % (60 * 60)) / 60;
int seconds = ans % 60;
String formattedTime = String.format("%02d:%02d:%02d", hours, minutes, seconds);
System.out.println(formattedTime);
}
}
'Problem Solving > 구현' 카테고리의 다른 글
BOJ1236 성지키기 (1) | 2024.01.29 |
---|---|
BOJ10158 개미 (0) | 2024.01.29 |
BOJ1543 문서검색 (0) | 2024.01.24 |
BOJ1919 애너그램만들기 (0) | 2024.01.24 |
BOJ2744 대소문자 바꾸기 (0) | 2024.01.24 |