-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
34 lines (26 loc) · 725 Bytes
/
Main.java
File metadata and controls
34 lines (26 loc) · 725 Bytes
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
32
33
34
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int pay = sc.nextInt();
int change = 1000 - pay;
int cnt = 0;
for(int coin : new int[]{500, 100, 50, 10, 5, 1}){
cnt += change / coin;
change %= coin;
}
/*
int[] coins = {500, 100, 50, 10, 5, 1};
while(change != 0){
for(int i=0; i<coins.length; i++){
while(coins[i] <= change){
change = change - coins[i];
cnt++;
}
}
}
*/
System.out.println(cnt);
sc.close();
}
}