본문 바로가기
알고리즘

[C] 백준 2939

by mokhwasomssi 2021. 3. 12.

일단 5로 나누고 

5로 나눈 나머지를 이용해서 3kg짜리 봉지가 몇 개 필요한지 판단

 

#include <stdio.h>

int main()
{
	int N = 0;
	scanf("%d", &N);

	if (N % 5 == 0)
		printf("%d", N / 5);

	else if (N % 5 == 1)
	{
		if (N - 5 > 0)
			printf("%d", N / 5 - 1 + 2);
		else
			printf("-1");
	}
	
	else if (N % 5 == 2)
	{
		if (N - 10 > 0)
			printf("%d", N / 5 - 2 + 4);
		else
			printf("-1");
	}

	else if (N % 5 == 3)
		printf("%d", N / 5 + 1);

	else if (N % 5 == 4)
	{
		if (N - 5 > 0)
			printf("%d", N / 5 - 1 + 3);
		else
			printf("-1");
	}

	return 0;
}