Пример #1
0
        public static void Main()
        {
            long bagLimit = long.Parse(Console.ReadLine());
            Bag  bag      = new Bag(bagLimit);

            string[] seif = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < seif.Length; i += 2)
            {
                long   amount = long.Parse(seif[i + 1]);
                string value  = seif[i];

                if (value.Length == 3)
                {
                    Cash cash = new Cash(value, amount);
                    bag.AddCash(cash);
                }

                if (value.ToLower().EndsWith("gem") && value.Length >= 4)
                {
                    Gem gem = new Gem(value, amount);
                    bag.AddGem(gem);
                }

                if (value.ToLower() == "gold")
                {
                    Gold gold = new Gold(amount);
                    bag.AddGold(gold);
                }
            }

            Console.WriteLine(bag);
        }
Пример #2
0
        static void Main(string[] args) // 50/100
        {
            int capacity = int.Parse(Console.ReadLine());

            bag = new Bag(capacity);

            string[] treasure = Console.ReadLine()
                                .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < treasure.Length; i += 2)
            {
                string name     = treasure[i];
                int    quantity = int.Parse(treasure[i + 1]);

                if (name.ToLower() == "gold")
                {
                    bag.AddGold(quantity);
                }
                else if (name.ToLower().EndsWith("gem"))
                {
                    bag.AddGem(name, quantity);
                }
                else if (name.Length == 3)
                {
                    bag.AddCash(name, quantity);
                }
            }

            Console.Write(bag);
        }
        public void AddItems()
        {
            string input = Console.ReadLine();

            string[] content = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < content.Length; i += 2)
            {
                string name     = content[i];
                long   quantity = long.Parse(content[i + 1]);

                if (name.Length == 3)
                {
                    Item newCash = new Item(name, quantity);
                    this.cashList.Add(newCash);
                }
                else if (name.Length >= 4 && name.ToLower().EndsWith("gem"))
                {
                    Item newGem = new Item(name, quantity);
                    this.gemList.Add(newGem);
                }
                else if (name.ToLower().Equals("gold"))
                {
                    Item newGold = new Item(name, quantity);
                    this.goldList.Add(newGold);
                }
            }

            bag.AddGold(goldList);
            bag.AddGems(gemList);
            bag.AddCash(cashList);
        }
Пример #4
0
        static void Main(string[] args)
        {
            long bagCapacity = long.Parse(Console.ReadLine());
            Bag bag = new Bag(bagCapacity);


            string[] itemsInput = ItemsInput();

            for (int i = 0; i < itemsInput.Length; i += 2)
            {
                string currentItem = itemsInput[i];
                long currentItemValue = long.Parse(itemsInput[i + 1]);

                if (currentItem.Length < 3)
                {
                    continue;
                }

                if (bag.Capacity < bag.CurrentCapacity + currentItemValue)
                {
                    continue;
                }
                
                string itemType;

                if (currentItem.Length == 3)
                {
                    itemType = "Cash";
                }
                else if (currentItem.ToLower().EndsWith("gem"))
                {
                    itemType = "Gem";
                }
                else if (currentItem.ToLower() == "gold")
                {
                    itemType = "Gold";
                }
                else
                {
                    continue;
                }

                switch (itemType)
                {
                    case "Gem":
                        bag.AddGem(currentItem, currentItemValue);
                        break;
                    case "Cash":
                        bag.AddCurrency(currentItem, currentItemValue);
                        break;
                    case "Gold":
                        bag.AddGold(currentItemValue);
                        break;
                }
            }

            bag.Print();
        }
        public void EngineStart(long bagCapacity, string[] safe)
        {
            var bag = new Bag();

            for (var i = 0; i < safe.Length; i += 2)
            {
                var name     = safe[i];
                var quantity = long.Parse(safe[i + 1]);

                var typeOfTreasure = string.Empty;

                if (name.Length == 3)
                {
                    typeOfTreasure = "Cash";
                }
                else if (name.ToLower().EndsWith("gem"))
                {
                    typeOfTreasure = "Gem";
                }
                else if (name.ToLower() == "gold")
                {
                    typeOfTreasure = "Gold";
                }

                if (typeOfTreasure == "")
                {
                    continue;
                }

                if (bagCapacity < bag.TotalQuantity + quantity)
                {
                    continue;
                }

                switch (typeOfTreasure)
                {
                case "Gem":
                    if (bag.TotalGoldAmount >= bag.TotalGemAmount + quantity)
                    {
                        bag.AddGems(name, quantity);
                    }
                    break;

                case "Cash":
                    if (bag.TotalGemAmount >= bag.TotalCashAmount + quantity)
                    {
                        bag.AddCash(name, quantity);
                    }
                    break;

                case "Gold":
                    bag.AddGold(name, quantity);
                    break;
                }
            }

            Console.WriteLine(bag);
        }
Пример #6
0
        public void Run()
        {
            long input = long.Parse(Console.ReadLine());

            string[] treasor = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var bag = new Bag(input);

            for (int i = 0; i < treasor.Length; i += 2)
            {
                string name  = treasor[i];
                long   count = long.Parse(treasor[i + 1]);

                string whatIsTheTreasure = string.Empty;

                if (name.Length == 3)
                {
                    whatIsTheTreasure = "Cash";
                }
                else if (name.ToLower().EndsWith("gem"))
                {
                    whatIsTheTreasure = "Gem";
                }
                else if (name.ToLower() == "gold")
                {
                    whatIsTheTreasure = "Gold";
                }

                if (whatIsTheTreasure == "")
                {
                    continue;
                }

                switch (whatIsTheTreasure)
                {
                case "Gem":
                    var currGem = new Gem(name, count);
                    bag.AddGems(currGem);
                    break;

                case "Cash":
                    var currCash = new Cash(name, count);
                    bag.AddCash(currCash);
                    break;

                case "Gold":
                    bag.AddGold(count);
                    break;
                }
            }
            Console.WriteLine(bag);
        }
Пример #7
0
        static void Main(string[] args)
        {
            long capacityOfTheBag = long.Parse(Console.ReadLine());

            string[] seif = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            //var bag = new Dictionary<string, Dictionary<string, long>>();
            Bag bag = new Bag();

            //long gold = 0;
            //long gems = 0;
            //long cash = 0;

            for (int i = 0; i < seif.Length; i += 2)
            {
                string name   = seif[i];
                long   amount = long.Parse(seif[i + 1]);

                string itemName = string.Empty;

                if (name.Length == 3)
                {
                    itemName = "Cash";
                }
                else if (name.ToLower().EndsWith("gem"))
                {
                    itemName = "Gem";
                }
                else if (name.ToLower() == "gold")
                {
                    itemName = "Gold";
                }

                if (itemName == "")
                {
                    continue;
                }
                else if (capacityOfTheBag < bag.SumAllInBag() + amount)
                {
                    continue;
                }

                switch (itemName)
                {
                case "Gem":
                    if (capacityOfTheBag >= (bag.SumAllInBag() + amount))
                    {
                        if (bag.SumGold() >= bag.SumAllGems() + amount)
                        {
                            bag.AddGems(name, amount);
                        }
                    }
                    break;

                ////if (!bag.ContainsKey(itemName))
                //if (!bag.CheckExistGems())
                //{
                //    //if (bag.ContainsKey("Gold"))
                //    if (bag.CheckExistGold())
                //    {
                //        //if (broika > bag["Gold"].Values.Sum())
                //        if (amount > bag.SumGold())
                //        {
                //            bag.CreateGems(name, amount);
                //            //continue;
                //        }
                //    }
                //}
                //else if (bag.SumAllGems() + amount > bag.SumGold())
                //{
                //    bag.AddGems(name, amount);
                //    //continue;
                //}
                //break;
                case "Cash":
                    if (capacityOfTheBag >= (bag.SumAllInBag() + amount))
                    {
                        if (bag.SumAllGems() >= bag.SumAllCash() + amount)
                        {
                            bag.AddCash(name, amount);
                        }
                    }
                    break;
                //if (!bag.CheckExistCash())
                //{
                //    if (bag.CheckExistGems())
                //    {
                //        if (amount > bag.SumAllGems())
                //        {
                //            bag.CreateCash(name, amount);
                //            //continue;
                //        }
                //    }
                //    else
                //    {
                //        bag.AddCash(name, amount);
                //        //continue;
                //    }
                //}

                ////else if (bag[itemName].Values.Sum() + amount > bag["Gem"].Values.Sum())
                //else if (bag.SumAllCash() + amount > bag.SumAllGems())
                //{
                //    bag.AddCash(name,amount);
                //    //continue;
                //}
                //break;
                case "Gold":
                    if (capacityOfTheBag >= (bag.SumAllInBag() + amount))
                    {
                        bag.AddGold(amount);
                    }
                    break;
                }

                //if (!bag.ContainsKey(itemName))
                //{
                //    bag[itemName] = new Dictionary<string, long>();
                //}

                //if (!bag[itemName].ContainsKey(name))
                //{
                //    bag[itemName][name] = 0;
                //}

                //bag[itemName][name] += amount;
                //if (itemName == "Gold")
                //{
                //    gold += amount;
                //}
                //else if (itemName == "Gem")
                //{
                //    gems += amount;
                //}
                //else if (itemName == "Cash")
                //{
                //    cash += amount;
                //}
            }
            //var resultGold = bag.GetAllGold();
            //var resultCash = bag.GetAllCash();
            //var resultGems = bag.GetAllGems();
            //resultGems = resultGems.OrderByDescending(x => x.Name).ToList();
            //resultCash = resultCash.OrderByDescending(x => x.Name).ToList();

            Console.WriteLine(bag);
            //Console.WriteLine(resultGold);


            //foreach (var currentGems in resultGems)
            //{
            //    Console.WriteLine($"{currentGems.Name} {currentGems.Quantity}");
            //}

            //foreach (var currentCash in resultCash)
            //{
            //    Console.WriteLine($"{currentCash.Name} {currentCash.Quantity}");
            //}

            //foreach (var x in bag)
            //{
            //    Console.WriteLine($"<{x.Key}> ${x.Value.Values.Sum()}");
            //    foreach (var item2 in x.Value.OrderByDescending(y => y.Key).ThenBy(y => y.Value))
            //    {
            //        Console.WriteLine($"##{item2.Key} - {item2.Value}");
            //    }
            //}
        }
Пример #8
0
        static void Main(string[] args)
        {
            long Capacity = long.Parse(Console.ReadLine());

            string[] safe = Console.ReadLine()
                            .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            // var bag = new Dictionary<string, Dictionary<string, long>>();
            //long gold = 0;
            //long stones = 0;
            //long cash = 0;
            Bag bag = new Bag();

            for (int i = 0; i < safe.Length; i += 2)
            {
                string nameOfItem = safe[i];
                long   amountItem = long.Parse(safe[i + 1]);

                string type = string.Empty;

                if (nameOfItem.Length == 3)
                {
                    type = "Cash";
                }
                else if (nameOfItem.ToLower().EndsWith("gem"))
                {
                    type = "Gem";
                }
                else if (nameOfItem.ToLower() == "gold")
                {
                    type = "Gold";
                }
                else
                {
                    continue;
                }

                if (Capacity < bag.TotalCapacity() + amountItem)
                {
                    continue;
                }

                if (type == "Gold")
                {
                    bag.AddGold(amountItem);
                }
                else if (type == "Gem")
                {
                    Gem gem = new Gem(nameOfItem, amountItem);
                    if (bag.Gold >= bag.SumGems() + amountItem)
                    {
                        bag.AddGem(gem);
                    }
                }
                else if (type == "Cash")
                {
                    Cash cash = new Cash(nameOfItem, amountItem);
                    if (bag.SumGems() >= bag.SumCash() + amountItem)
                    {
                        bag.AddCash(cash);
                    }
                }
            }

            Console.WriteLine(bag);
        }