백준 문제풀이

[백준 BAEKJOON] 2884번 : 알람 시계 ( C언어 )

hsminnnn 2022. 11. 18. 12:28

 

 

 

 

 

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

 

2884번: 알람 시계

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

www.acmicpc.net

 

 

 

 

문제

 

 

 

 

소스 코드
#include <stdio.h>
int main() {
	int H, M;
	scanf("%d %d", &H, &M);
    
	if (H == 0) {
		if (M < 45) {
			H = 23; M = M + 60 - 45;
			printf("%d %d", H, M);
		}
		else if (M >= 45) {
			M = M - 45;
			printf("%d %d", H, M);
		}
	}
	else if (H > 0) {
		if (M < 45) {
			H = H - 1; M = M + 60 - 45;
			printf("%d %d", H, M);
		}
		else if (M >= 45) {
			M = M - 45;
			printf("%d %d", H, M);
		}
	}
	return 0;
}

 

 

 

 

 

결과