JAVA/백준

[Java11] 2884번 : 알람 시계

lavender1122 2024. 9. 8. 17:33

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

 

정답

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        StringTokenizer st = new StringTokenizer(str, " ");
        int H = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        
        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));
        }
    }
}
  • 만약 분이 45분 보다 작다면 
    • 시간에서 -1 빼고
    • 시간이 0보다 작다면 23으로 대입
  • 만약 분이 45분 보다 크다면
    • 분에서 - 45 해라