boj)5585

2020. 8. 24. 23:24PS/boj

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static int T, money, count;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        T = Integer.parseInt(br.readLine());
        money = 1000 - T;

        count += money / 500;
        count += money % 500 /100;
        count += money % 500 % 100 / 50;
        count += money % 500 % 100 % 50 / 10;
        count += money % 500 % 100 % 50 % 10 / 5;
        count += money % 500 % 100 % 50 % 10 % 5 ;

        System.out.println(count);
    }

}

 

- 먼가 구질구질한듯 

- 근데 이렇게 밖에 생각이 안났음

 

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static int money, count;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        money = 1000 - Integer.parseInt(br.readLine());

        int[] changes = {500, 100, 50, 10, 5, 1};

        for (int cha : changes) {
            int x = money / cha; // 몫
            if (x > 0) {
                money -= cha * x;
                count += x;
            }

            if (money == 0) {
                break;
            }
        }

        System.out.println(count);
    }

}

 

- 다른 코드 참조해서 약간 업그레이드

- 애초에 잔돈을 배열에 담아서 for문 돌렸음 

'PS > boj' 카테고리의 다른 글

boj)1431  (0) 2020.08.28
boj)1181  (0) 2020.08.28
boj)10162  (0) 2020.08.24
boj)11966  (0) 2020.08.24
boj)18110  (0) 2020.08.24