-
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문 돌렸음