[BaekJoon] 10162번 - 전자레인지 [Java][C++]
[BaekJoon] 10162번 - 전자레인지 [Java][C++]
1. 문제 풀이
각 버튼이 서로 배수 관계에 있어서 최소 조작을 하려면 지정된 시간이 큰 버튼부터 누르면 된다.
2. 코드
1. 풀이 [Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
int A = T / 300;
T %= 300;
int B = T / 60;
T %= 60;
int C = T / 10;
T %= 10;
if (T == 0) {
System.out.println(A + " " + B + " " + C);
} else {
System.out.println(-1);
}
}
}
2. 풀이 [C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
int a = t / 300;
t %= 300;
int b = t / 60;
t %= 60;
int c = t / 10;
t %= 10;
if (t) {
cout << -1;
} else {
cout << a << ' ' << b << ' ' << c;
}
}
This post is licensed under CC BY 4.0 by the author.