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); }
static void Main(string[] args) { long bagCapacity = long.Parse(Console.ReadLine()); IBag bag = new Bag(bagCapacity); string[] safe = Console.ReadLine() .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < safe.Length; i += 2) { string name = safe[i]; long count = long.Parse(safe[i + 1]); string item = string.Empty; item = SelectItem(name); long bagOcupate = bag.OcupateBag; if (item == "Gold") { bag.Gold += count; } else if (item == "Gem") { bag.AddGem(name, count); } else if (item == "Cash") { bag.AddCash(name, count); } } Console.WriteLine(bag.PrintResult()); }
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); }
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 CollectItems(Bag bag, string[] safeContent) { Parser parser = new Parser(); for (int i = 0; i < safeContent.Length; i += 2) { string inputName = safeContent[i]; long quantity = long.Parse(safeContent[i + 1]); string name = parser.ParseItem(inputName); if (bag.Capacity >= (bag.TotalAmount + quantity)) { switch (name) { case "gem": if (bag.TotalGemsAmount + quantity <= bag.Gold.Amount) { bag.AddGem(name, quantity); bag.AddItem(name, quantity); } break; case "cash": if (bag.TotalCashAmount + quantity <= bag.TotalGemsAmount) { bag.AddCash(name, quantity); bag.AddItem(name, quantity); } break; case "gold": bag.Gold.AddAmount(quantity); bag.AddItem(name, quantity); break; } } else { continue; } } }
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); }