Algorithm/나머지 문제들
[Baekjoon/JAVA] 백준 2884번 알람 시계
양선규
2023. 6. 26. 18:33
728x90
반응형
즉, 입력받은 시간의 45분 전 시간을 출력하면 되는 문제입니다.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
if(b >= 45){
System.out.println(a+" "+(b-45));
}
else if(a == 0){
System.out.println("23 "+(b+15));
}
else{
System.out.println((a-1)+" "+(b+15));
}
}
}
a를 시, b를 분 이라고 합시다.
1번 조건 : b가 45 이상일 경우 -> b - 45 / a는 그대로
10시 55분 -> 10시 10분
22시 50분 -> 22시 5분
7시 45분 -> 7시 0분
2번 조건 : b가 45 미만일 경우 -> b + 15 / a - 1
단, a가 0일 경우 a = 23 이어야 합니다. ( 0시의 전 시간은 23시 )
21시 40분 -> 20시 55분
9시 30분 -> 8시 45분
3시 10분 -> 2시 25분
0시 40분 -> 23시 55분
위의 조건을 기반으로 if문을 사용하여 문제를 해결하였습니다.
728x90
반응형