본문 바로가기
Algorithm/Beakjoon

[Java] baekjoon 2884 : 알람 시계 / if문

by Amy97 2021. 7. 26.
728x90

문제 


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

 

2884번: 알람 시계

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

www.acmicpc.net

구현 


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
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
 
        int h = sc.nextInt();
        int m = sc.nextInt();
 
        if (m - 45 >= 0) {
            m -= 45;
        }
 
        else if (m - 45 < 0) {
            m += 15;
            h--;
        }
 
        if (h < 0) {
            h = 23;
        }
        System.out.println(h + " " + m);
 
    }
}
cs

결과 


728x90

댓글