거스름돈이 잔돈의 단위보다 큰 금액이라면, 거스름돈에서 잔돈의 단위를 뺀다.
거스름돈이 잔돈의 단위보다 작다면, 잔돈의 단위를 감소시킨다.
import java.util.Scanner;
public class Main {
static int[] coin = {500, 100, 50, 10, 5, 1};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int change = 1000 - N;
int num = 0;
while (change >= coin[0]) {
change -= coin[0];
num++;
}
while (change >= coin[1]) {
change -= coin[1];
num++;
}
while (change >= coin[2]) {
change -= coin[2];
num++;
}
while (change >= coin[3]) {
change -= coin[3];
num++;
}
while (change >= coin[4]) {
change -= coin[4];
num++;
}
while (change >= coin[5]) {
change -= coin[5];
num++;
}
System.out.println(num);
}
}
import java.util.Scanner;
public class Main {
static int[] coin = {500, 100, 50, 10, 5, 1};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int change = 1000 - N;
int num = 0;
int k = 0;
while (change > 0) {
if (change >= coin[k]) {
change -= coin[k];
num++;
} else {
k++;
}
}
System.out.println(num);
}
}