알고리즘/백준

2884 - 알람 시계

leegeonwoo 2023. 8. 15. 12:12

✏️문제풀이

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