흔한 QA 엔지니어

[백준] 2884번 : 알람 시계 - JAVA 본문

BAEKJOON

[백준] 2884번 : 알람 시계 - JAVA

블로그 닉네임 입력 제한 수는 몇 자인가요? 2025. 9. 22. 16:39

https://www.acmicpc.net/problem/2884

시간과 분을 분리해서 계산하는 것이 중요합니다.
주어진 시간에 45분을 빼면 되는데
시간 단위가 0일 때와 분 단위가 45분보다 작을 때의 조건을 주고 계산합니다. 

import java.util.*;

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){
        	System.out.println(H + " " +  (M - 45));
        	
        } else {
            if(H == 0){
                System.out.println(23 + " " + (60 - (45 - M)));         
            } else {
                System.out.println((H - 1) + " " + (60 - (45 - M)));
        
            }
        }
    }
}