728x90
어제 포스팅한 알람시계와 거의 동일한 문제다.
푸는 방식은 똑같다.
2022.07.27 - [알고리즘] - [백준] 2884 알람시계 (Java)
[백준] 2884 알람시계 (Java)
알고리즘 입문으로 상당히 괜찮은 문제다. 아마 프로그래밍을 이제 막 시작한 사람들은 한 번 쯤 거쳐가는 문제이지 않을까..? import java.io.BufferedReader; import java.io.IOException; import java.io.Inpu..
codari.tistory.com
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
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 h = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(br.readLine());
int nH, nM; // 기존 시간에서 더한 시간을 통째로 저장하기 위한 변수
nH = h;
nM = m + c;
while (nM >= 60) { // 분이 60분을 넘으면 시간을 더해주고, 시간이 24시간이 넘으면 0으로 초기화한다.
nM -= 60;
nH += 1;
if (nH >= 24) {
nH = 0;
}
}
System.out.println(nH + " " + nM);
}
}
728x90
'알고리즘' 카테고리의 다른 글
[백준] 1712 손익분기점 (Java) (0) | 2022.08.09 |
---|---|
[백준] 2525 오븐시계 (Python) (0) | 2022.07.29 |
[백준] 2884 알람시계 (Python) (0) | 2022.07.27 |
[백준] 2884 알람시계 (Java) (0) | 2022.07.27 |
[백준] 4344 평균은넘겠지 (Java) (0) | 2022.07.27 |