6일차 설탕공장 알고리즘(최대한 적은 수의 봉지로 배달하기)

Console Programming/C# Console 2019. 9. 25. 14:13

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax15
{
    class Program
    {
        static void Main(string[] args)
        {
           
                int input = Int32.Parse(Console.ReadLine());            
                int quotient=0;
                bool isRemain=false;
            
                for (int i = input/5; i >-1; i--)
                {
                    for (int j = input/3; j >-1; j--)
                    {
                        isRemain = (input == (5 * i + 3 * j));
                        //Console.WriteLine($"isRemain = {isRemain}, i = {i}, j={j} ");
                        if (isRemain)
                        {
                            quotient = i + j;
                           //Console.WriteLine($"quotient={quotient}");
                            break;
                        }
                    }
                    if(isRemain)
                    { break;
                    }
                }
                if (isRemain)
                {
                    Console.WriteLine(quotient);
                }
                else
                {
                    Console.WriteLine(-1);
                }
            
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

: