[백준] 2525번 - 오븐 시계 [Java][C++]
[백준] 2525번 - 오븐 시계 [Java][C++]
1. 문제 풀이
현재 시각을 의미하는 두 정수 $A$, $B$ 가 주어졌을 때, $C$ 분 이후 시각을 출력해야 하는 문제이다.
$B + C$ 를 $60$ 으로 나눈 몫만큼 시 정보가 증가하고, 나머지가 분 정보가 되며, 시 정보는 $24$ 주기로 $0$ 이 되므로 $24$ 로 나눠주면 된다.
2. 코드
1. 사칙연산 [Java]
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);
}
}
2. 사칙연산 [C++]
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, c;
cin >> a >> b >> c;
cout << (a + (b + c) / 60) % 24 << ' ' << (b + c) % 60;
}
3. 풀이 정보
1. 사칙연산 [Java]
| 언어 | 시간 | 메모리 | 코드 길이 |
|---|---|---|---|
| Java 11 | 124 ms | 16024 KB | 503 B |
2. 사칙연산 [C++]
| 언어 | 시간 | 메모리 | 코드 길이 |
|---|---|---|---|
| C++ 17 | 0 ms | 2020 KB | 219 B |
This post is licensed under CC BY 4.0 by the author.