코딩테스트/백준(JAVA)

백준 코딩테스트 2-6-2525 오븐 시계 코딩 문제 java로 푸는 방법

쏠솔랄라 2023. 3. 10. 17:09

 

 

백준 코딩테스트 단계별로 풀어보기

2단계 조건문 6단계 2525 오븐 시계 문제입니다

 

 

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

 

2525번: 오븐 시계

첫째 줄에 종료되는 시각의 시와 분을 공백을 사이에 두고 출력한다. (단, 시는 0부터 23까지의 정수, 분은 0부터 59까지의 정수이다. 디지털 시계는 23시 59분에서 1분이 지나면 0시 0분이 된다.)

www.acmicpc.net

 

 

https://www.acmicpc.net/step

 

단계별로 풀어보기

단계별은 @jh05013님이 관리하고 계십니다. 단계제목설명정보총 문제내가 맞은 문제1입출력과 사칙연산입력, 출력과 사칙연산을 연습해 봅시다. Hello World!132조건문if 등의 조건문을 사용해 봅시다

www.acmicpc.net

 

 


 

 

 

 

문제
KOI 전자에서는 건강에 좋고 맛있는 훈제오리구이 요리를 간편하게 만드는 인공지능 오븐을 개발하려고 한다.
인공지능 오븐을 사용하는 방법은 적당한 양의 오리 훈제 재료를 인공지능 오븐에 넣으면 된다. 그러면 인공지능 오븐은 오븐구이가 끝나는 시간을 분 단위로 자동적으로 계산한다. 
또한, KOI 전자의 인공지능 오븐 앞면에는 사용자에게 훈제오리구이 요리가 끝나는 시각을 알려 주는 디지털 시계가 있다. 
훈제오리구이를 시작하는 시각과 오븐구이를 하는 데 필요한 시간이 분단위로 주어졌을 때, 오븐구이가 끝나는 시각을 계산하는 프로그램을 작성하시오.

입력
첫째 줄에는 현재 시각이 나온다.
현재 시각은 시 A (0 ≤ A ≤ 23) 와 분 B (0 ≤ B ≤ 59)가 정수로 빈칸을 사이에 두고 순서대로 주어진다.
두 번째 줄에는 요리하는 데 필요한 시간 C (0 ≤ C ≤ 1,000)가 분 단위로 주어진다. 

출력
첫째 줄에 종료되는 시각의 시와 분을 공백을 사이에 두고 출력한다.
(단, 시는 0부터 23까지의 정수, 분은 0부터 59까지의 정수이다.
디지털 시계는 23시 59분에서 1분이 지나면 0시 0분이 된다.)

 

정답

import java.util.Scanner;

public class Main {

public static void main(String [] args) {

 

Scanner sc = new Scanner (System.in);

int A = sc.nextInt();

int B = sc.nextInt();

int C = sc.nextInt();

sc.close();

 

A += C/60; 

B += C%60;

 

if (B >= 60){

B-=60;

A++;

}

 

if (A >= 24) {

A-=24;

}

 

System.out.println(A + " " + B);

}

}

 

=>

요리시간이 60분을 넘을 때마다 시간(A)에 추가

요리시간을 시간단위로 나누고 남은 나머지를 분(B)에 추가

 

B가 60을 넘으면 60을 빼 주고

A는 1시간 추가

 

A가 24시간이 되면 0으로 반환

 

 

// 다른 방법으로 풀었던 것 

import java.util.Scanner;

public class Main {

public static void main(String [] args) {

 

Scanner sc = new Scanner (System.in);

int A = sc.nextInt();

int B = sc.nextInt();

int C = sc.nextInt();

sc.close();

 

int totMin = A*60+B+C;

int hour = (totMin/60)%24;

int min = totMin%60;

 

System.out.println(hour + " " + min);

}

}

 

=>

입력받은 A, B, C를 모두 분으로 바꾼 후(totMin)

바꾼 분을 다시 시간(hour)과 분(min)으로 나눔

시간은 다시 24시간의 나머지로 구하면 24단위로 초기화

 

 


 

 

1-1-2557 Hello World https://developernew.tistory.com/41 <- 백준 답지 제출 방법
1-2-1000 A+B https://developernew.tistory.com/42
1-3-1001 A-B https://developernew.tistory.com/43
1-4-10998 AXB https://developernew.tistory.com/44
1-5-1008 A/B https://developernew.tistory.com/45
1-6-10869 사칙연산 https://developernew.tistory.com/46
1-7-10926 ??! https://developernew.tistory.com/47
1-8-18108 1998년생인 내가 태국에서는 2541년생?! https://developernew.tistory.com/48
1-9-10430 나머지 https://developernew.tistory.com/49
1-10-2588 곱셈 https://developernew.tistory.com/50
1-11-11382 꼬마 정민 https://developernew.tistory.com/51
1-12-10171 고양이 https://developernew.tistory.com/52
1-13-10172 개 https://developernew.tistory.com/53

2-1-1330 두 수 비교하기 https://developernew.tistory.com/54
2-2-9498 시험 성적 https://developernew.tistory.com/55
2-3-2753 윤년 https://developernew.tistory.com/56
2-4-14681 사분면 고르기 https://developernew.tistory.com/61
2-5-2884 알람 시계 https://developernew.tistory.com/68