본문 바로가기
JAVA/백준

[백준/자바] 14916번 거스름돈

by 동백05 2022. 2. 16.

https://www.acmicpc.net/problem/14916

 

14916번: 거스름돈

첫째 줄에 거스름돈 액수 n(1 ≤ n ≤ 100,000)이 주어진다.

www.acmicpc.net

import java.util.Scanner;
public class feb16 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int cost=s.nextInt();
		s.close();
		int count=0;
		while(cost>0) {
			if(cost%5==0) {
				count+=cost/5;
				break;
			}
			cost-=2;
			count++;
			if(cost<0) {
				count=-1;
				break;
			}
		}
		System.out.print(count);

	}

}

댓글