Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

Hennie

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

BaekJoon/02. if문

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

헨니 2021. 4. 12. 18:37

 

QUESTION

www.acmicpc.net/problem/2884

 

2884번: 알람 시계

상근이는 매일 아침 알람을 듣고 일어난다. 알람을 듣고 바로 일어나면 다행이겠지만, 항상 조금만 더 자려는 마음 때문에 매일 학교를 지각하고 있다. 상근이는 모든 방법을 동원해보았지만,

www.acmicpc.net

 

ANSWER

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int m = scan.nextInt();
		int real = m - 45;
		if(real < 0) {
			real = real + 60;
			h--;
			if(h < 0) {
				h = h + 24;
			}
			System.out.print(h + " ");
			System.out.println(real);
		} else {
			System.out.print(h + " ");
			System.out.println(real);
		}
	}
}

 

RESULT

 

MEMO

상근님.. 45분 일찍 알람 하나를 맞춘다고 해서 달라지는 건 없어요..

9시 20분에 일어나야 한다면 한 시간 전부터

5 ~10분간격으로 알람을 맞춰야만 일어날 수 있습니다..