문제
I.O
코드 및 해석
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Boj_5585 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int pay = Integer.parseInt(br.readLine());
int change = 1000 - pay;
int cntSum = 0;
int[] changeCnt = new int[3];
changeCnt[0] = change / 100;
changeCnt[1] = change % 100 / 10;
changeCnt[2] = change % 10;
for(int i = 0 ; i < changeCnt.length ; i++) {
if(changeCnt[i] >= 5) {
changeCnt[i] -= 4;
}
cntSum += changeCnt[i];
}
System.out.println(cntSum);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Boj_5585 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int change = 1000 - Integer.parseInt(br.readLine());
int cntSum = 0;
int[] changeCnt = { 500, 100, 50, 10, 5, 1 };
int i = 0;
while(change != 0) {
while(change / changeCnt[i] != 0) {
cntSum += change / changeCnt[i];
change %= changeCnt[i];
}
i++;
}
System.out.println(cntSum);
}
}
문제 및 사진출처
출처 - 백준 알고리즘_5585번