[BOJ] 2525

Organ·2023년 9월 1일
0

[문제 풀이]

목록 보기
6/123

오븐 시계

문제

입력

출력

예제

내 풀이

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) throws IOException {
    
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String str;
		int a,b,c;


		str = br.readLine();
		StringTokenizer st = new StringTokenizer(str);

		a = Integer.parseInt(st.nextToken());
		b = Integer.parseInt(st.nextToken());

		c = Integer.parseInt(br.readLine());
		
		b += c;

		while (b >= 60)
		{
			a += 1;
			b -= 60;
		}
				
		if(a >= 24)
			a -= 24;

		System.out.printf("%d %d", a, b);

	}
}

다른 풀이

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
 
public class Main {
    public static void main(String[] args) throws IOException {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());
 
        int C = Integer.parseInt(br.readLine());
 
        int min = 60 * A + B;   // 시 -> 분
        min += C;
 
        int hour = (min / 60) % 24;
        int minute = min % 60;
 
        System.out.println(hour + " " + minute);
 
    }
}

출처

https://st-lab.tistory.com/292

0개의 댓글