https://www.acmicpc.net/problem/1408
1408번: 24
도현이는 Counter Terror Unit (CTU)에서 일하는 특수요원이다. 도현이는 모든 사건을 정확하게 24시간이 되는 순간 해결하는 것으로 유명하다. 도현이는 1시간 만에 범인을 잡을 수 있어도 잡지 않는
www.acmicpc.net
> 풀이
import java.util.Scanner;
/*
* boj 1408 24
* #bronze2
* #수학
*/
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String[] startTime = sc.nextLine().split(":");
String[] endTime = sc.nextLine().split(":");
int startHour = Integer.parseInt(startTime[0]);
int startMin = Integer.parseInt(startTime[1]);
int startSec = Integer.parseInt(startTime[2]);
int endHour = Integer.parseInt(endTime[0]);
int endMin = Integer.parseInt(endTime[1]);
int endSec = Integer.parseInt(endTime[2]);
String[] answer = new String[5];
answer[1] = answer[3] = ":";
if(endSec - startSec < 0) {
endMin--;
endSec += 60;
}
if(endMin - startMin < 0) {
endHour--;
endMin += 60;
}
if(endHour - startHour < 0) {
endHour += 24;
}
answer[4] = String.valueOf(endSec - startSec);
answer[2] = String.valueOf(endMin - startMin);
answer[0] = String.valueOf(endHour - startHour);
for(String x : answer) {
if(x.length() == 1 && !":".equals(x)) {
System.out.print('0'+x);
} else {
System.out.print(x);
}
}
}
}
'PS > BOJ' 카테고리의 다른 글
백준 2292 벌집 / JAVA (0) | 2023.03.26 |
---|---|
백준 2145 숫자 놀이 / JAVA (0) | 2023.03.25 |
백준 12015 가장 긴 증가하는 부분 수열1(DP) / JAVA (0) | 2023.02.15 |
백준 1012 유기농배추(DFS,BFS) / JAVA (0) | 2023.02.03 |
백준 2667 단지번호붙이기(DFS,BFS) / JAVA (0) | 2023.02.01 |
댓글