백준 문제풀기/JAVA

[백준 2884 JAVA 자바] 알람 시계

냉동피자 2023. 8. 8. 22:31

 

시는 0~23

분은 0~59

 

알람 시계는 45분 앞서게

라는 뜻은 현재시간 + 45분 이죠

 

상근이가 설정한 시간을 창영이의 방법으로 바꿉시다

 

코드입니다

 

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int m = scan.nextInt();
		
		if(m>=45) {
			System.out.printf("%d %d",n,m-45);
		}else {
			if(n==0) {
				System.out.printf("23 %d",60-(45-m));
			}else {
				System.out.printf("%d %d",n-1,60-(45-m));
			}
		}
	}
}

 

n==0인 경우 즉 0시인 경우는

전날로 가야하기 때문에 추가적으로 경우를 설정해줍시다