Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

forDevLife

[백준] 10162 - 전자레인지 본문

알고리즘

[백준] 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 + " ");
        }
    }
}
Comments