https://www.acmicpc.net/problem/5585
5585번: 거스름돈
타로는 자주 JOI잡화점에서 물건을 산다. JOI잡화점에는 잔돈으로 500엔, 100엔, 50엔, 10엔, 5엔, 1엔이 충분히 있고, 언제나 거스름돈 개수가 가장 적게 잔돈을 준다. 타로가 JOI잡화점에서 물건을 사
www.acmicpc.net
- 접근
거스름 돈의 개수를 최소로해야하니 큰 돈부터 계산해 나가면됨
몫, 카운드 필요할 것
import java.util.*;
class B5585
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int inMoney = sc.nextInt();
int outMoney = 1000-inMoney;
int count = 0;
while (outMoney>0) //잔돈이 0이되면 반복문 탈출
{
count += outMoney/500;
outMoney = outMoney%500;
count += outMoney/100;
outMoney = outMoney%100;
count += outMoney/50;
outMoney = outMoney%50;
count += outMoney/10;
outMoney = outMoney%10;
count += outMoney/5;
outMoney = outMoney%5;
count += outMoney/1;
outMoney = outMoney%1;
}
System.out.println(count);
}
}
너무 쉬운 문제라 설명할 것이 없다..
'JAVA > Java 백준 문제풀이' 카테고리의 다른 글
자바, 백준 10162 전자레인지 (0) | 2022.05.08 |
---|---|
자바, 백준 1931 (0) | 2022.04.09 |
자바, 백준 11047 (0) | 2022.04.07 |
자바, 백준 11399 (0) | 2022.04.06 |
자바, 백준 2839 (0) | 2022.04.05 |