[BaekJoon] 2525번 - 오븐 시계 [Java][C++]
[BaekJoon] 2525번 - 오븐 시계 [Java][C++]
1. 문제 풀이
현재 시각을 의미하는 시($A$)와 분($B$)이 주어졌을 때, $C$ 분 이후 시각을 출력해야 하는 문제이다.
$A$ 시 $B$ 분에서 $C$ 분이 지난 시각은 $B + C$ 를 60으로 나눈 나머지가 분의 정보가 되며 몫과 $A$ 를 더한 값이 시의 정보가 된다. 이때 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;
}
This post is licensed under CC BY 4.0 by the author.