[BaekJoon] #2525 - 오븐 시계 [Java][C++]
[BaekJoon] #2525 - 오븐 시계 [Java][C++]
1. 아이디어
현재 시각을 의미하는 시와 분이 주어졌을 때, $C$분 이후 시각을 출력해야 하는 문제이다.
$A$시 $B$분에서 $C$분이 지난 시각은 $B + C$를 60으로 나눈 나머지가 분의 정보가 되며 몫과 $A$를 더한 값이 시의 정보가 된다. 이때 24시마다 0시가 되므로 시 정보도 24로 나눈 나머지가 실제 시각이 된다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.io.*;
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 a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(br.readLine());
System.out.println((a + (b + c) / 60) % 24 + " " + (b + c) % 60);
}
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
cout << (a + (b + c) / 60) % 24 << ' ' << (b + c) % 60;
}
This post is licensed under CC BY 4.0 by the author.