2884 - 알람 시계알고리즘/백준2023. 8. 15. 12:12
Table of Contents
✏️문제풀이
h는 시간, m은 분을 뜻하는 변수이다.
일반적으로 계산할 때 분이 00분보다 내려가게되면, 시간은 1시간빼고 분은 60분으로 리셋되어 계산한다.
거기서 만약 시간이 0보다 작다면, 시간은 24시(00시) - 1 인 23으로 맞춰준다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int m = sc.nextInt();
if(m < 45) {
h--;
m = 60 - (45-m);
if(h < 0) {
h = 23;
}
System.out.println(h + " " + m);
}else {
System.out.println(h + " " + (m - 45));
}
}
}
728x90
'알고리즘 > 백준' 카테고리의 다른 글
8393 - 합 (0) | 2023.08.16 |
---|---|
10950 - A + B - 3 (0) | 2023.08.16 |
2480 - 주사위 세개 (0) | 2023.08.15 |
2525 - 오븐 시계 (0) | 2023.08.15 |
[백준] - 18108 1998년생인 내가 태국에선 2541년생?! (0) | 2023.08.15 |
@leegeonwoo :: geonwoo
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!