ONLINE JUDGE/제어문

[백준2884] 알람 시계

W_W_Woody 2022. 1. 21. 01:46

 

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

 

2884번: 알람 시계

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

www.acmicpc.net


입력받은 분 값이 45보다 작으면 시-1 해주고, (분+60) - 입력값

아니라면 그냥 분-45

 

시가 0보다 작아지면 23으로 수정해준다.

import java.util.Scanner;

public class Day05_2884 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		if (m < 45) {
			h--;
			if(h<0) {
				h=23;
			}
			m = (m+60)-45;
			System.out.print(h+" "+ m);
		} else {
			m = m-45;
			System.out.print(h+" "+ m);
		}
	}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Day05_2884_2 {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
		int h = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());

		if (m < 45) {
			h--;
			if (h < 0) {
				h = 23;
			}
			m = (m + 60) - 45;
			System.out.print(h + " " + m);
		} else {
			m = m - 45;
			System.out.print(h + " " + m);
		}
	}
}