코테

[백준 14916] 거스름돈 JAVA

오은이 2023. 1. 24. 00:07

 

 


 

 

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;				//거스름돈 금액
		int x = 0;			//동전 개수
		n = sc.nextInt();	
		
		while(n >= 5) {
			if(n == 8 || n == 6)	//8과 6은 2로 거슬러줘야함
				break;
			n-= 5;
			x++;
		}
		if(n % 2 == 0) {
			while(n >= 2) {
				n-=2;
				x++;
			}
			System.out.println(x);
		}
		else {
			System.out.println(-1);
		}
	}
}

 

 

예제 1

 

예제 2

 

 

채점 결과

 

 

 

이번 문제는 나름 쉽게 푼 것 같다.