알고리즘
[백준] 10162 - 전자레인지
JH_Lucid
2021. 6. 8. 23:17
- 매우 간단한 그리디 알고리즘
- 제일 큰 수를 먼저 빼서, t를 갱신하고 10보다 작을때까지 while을 반복한다.
import java.io.IOException;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int[] arr = new int[3];
if(t%10 != 0) {
System.out.println(-1);
return;
}
while(t >= 10) {
if(t >= 300) {
t = t - 300;
arr[0]++;
} else if(t >=60) {
t = t - 60;
arr[1]++;
} else {
t = t - 10;
arr[2]++;
}
}
for(int x : arr) {
System.out.print(x + " ");
}
}
}