-
06/02 백준 코딩테스트 2839 설탕 배달코딩테스트 2021. 6. 2. 01:26
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int tmp = n / 5; int count5kg; int count3kg; bool bol = true; for (int i = tmp; i >= 0; i--) { count5kg = i; int a = n - (5 * count5kg); count3kg = a / 3; int b = count5kg * 5 + count3kg * 3; if (b == n) { Console.WriteLine(count3kg + count5kg); bol = false; break; } } if (bol) { Console.WriteLine(-1); } } } }
문제 푸는데 30분 정도 걸렸다.
'코딩테스트' 카테고리의 다른 글
08/19 코딩테스트 백준 5585 거스름돈 (0) 2021.08.19 08/19 코딩테스트 백준 1541 잃어버린 괄호 (0) 2021.08.19 08/19 백준 코딩테스트 1931 회의실 배정 (0) 2021.08.19 08/18 백준 코딩테스트 11047 동전 0 (0) 2021.08.18 06/02 백준 코딩테스트 11399 ATM (0) 2021.06.02