알고리즘/백준
[Python/Java] 백준 2884번 - 알람 시계
소꿍
2020. 6. 8. 16:50
https://www.acmicpc.net/problem/2884
2884번: 알람 시계
문제 상근이는 매일 아침 알람을 듣고 일어난다. 알람을 듣고 바로 일어나면 다행이겠지만, 항상 조금만 더 자려는 마음 때문에 매일 학교를 지각하고 있다. 상근이는 모든 방법을 동원해보았지
www.acmicpc.net
Python
H, M = map(int, input().split())
if M < 45 :
if H-1 < 0 :
print(24-abs(H-1), (60-abs(M-45)), sep=' ')
elif H-1 == 0:
print(0, (60-abs(M-45)), sep=' ')
else:
print(H-1, (60-abs(M-45)), sep=' ')
elif M >= 45 :
print(H, M-45, sep=' ')
else:
pass
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String[] s = scan.nextLine().split(" ");
int h = Integer.parseInt(s[0]);
int m = Integer.parseInt(s[1]);
// 분 체크
if (m < 45) {
m = 60 + (m - 45);
// 시 체크
if (h == 0) {
h = 23;
} else {
h -= 1;
}
} else {
m -= 45;
}
System.out.println(h + " " + m);
}
}