Information Security Study

[백준] 2884: 알람 시계 본문

Programming/C

[백준] 2884: 알람 시계

gayeon_ 2024. 1. 7. 18:09

 

입력된 시간보다 45분 이른 시간이 출력되면 된다.

 

 

 

#include <stdio.h>

int main() {

	int H;
    int M;
    
    scanf("%d %d", &H, &M);
    
    // 45분 이상인 경우
    if(H >= 0 && H <= 23 && M >= 45 && M <= 59) {
    	printf("%d %d", H, M-45);
    } else if(H > 0 && H <= 23 && M >= 0 && M <= 44) { // 45분 미만인 경우
    	printf("%d %d", H-1, M+15);
    } else { // 0시 45분 미만인 경우
    	printf("%d %d", H+23, M+15);
    }
    
    return 0;
    
}

세가지 경우로 나눠서 else if문으로 작성했다.

'Programming > C' 카테고리의 다른 글

[백준] 2480: 주사위 세개  (1) 2024.01.07
[백준] 2525: 오븐 시계  (0) 2024.01.07
[백준] 9498: 시험 성적  (0) 2024.01.07
[백준] 1330: 두 수 비교하기  (1) 2024.01.07
[백준] 10171: 고양이  (0) 2024.01.07