[설탕 배달]06-12

Algorithmus 2019. 6. 12. 15:53


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
 
namespace TestSugarDelivery
{
    public class App
    {
        public App()
        {
 
        }
 
        public void Start()
        {
            int a = 2;
            this.SugerDelivery(a);
            a = 3;
            this.SugerDelivery(a);
            a = 5;
            this.SugerDelivery(a);
            a = 7;
            this.SugerDelivery(a);
            a = 8;
            this.SugerDelivery(a);
            a = 11;
            this.SugerDelivery(a);
            a = 13;
            this.SugerDelivery(a);
            a = 15;
            this.SugerDelivery(a);
            a = 18;
            this.SugerDelivery(a);
        }
 
        public void SugerDelivery(int a)
        {
            Console.WriteLine("배달할 무게 : {0}", a);
            int suger = a;
            int kg5 = 0;
            int kg3 = 0;
 
            if (suger % 5 == 0)
            {
                kg5 = suger / 5;
                Console.WriteLine("설탕봉지 : {0}개", kg5 + kg3);
 
            }
            else
            {
                while (true)
                {
                    if (suger - 5 > 0)
                    {
                        suger -= 5;
                        kg5++;
                    }
                    if (suger % 3 == 0)
                    {
                        kg3 = suger / 3;
                        Console.WriteLine("설탕봉지 : {0}개", kg5 + kg3);
                        break;
                    }
                    if (suger - 5 < 0)
                    {
                        Console.WriteLine("-1");
                        break;
                    }
                }
            }
            Console.WriteLine();
        }
    }
}
cs


'Algorithmus' 카테고리의 다른 글

C# 10430 분배법칙  (0) 2021.10.25
20200811 임시, 추가 변수없이 두 정수값 교체  (0) 2020.08.11
AStar algorithm 4방향(캐릭터 이동)  (0) 2019.05.21
AStar algorithm  (0) 2019.05.20
[Palindrome Number]05-14  (0) 2019.05.14
: