public static void Main() { long capacity = long.Parse(Console.ReadLine()); string[] items = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); Bag bag = new Bag(capacity); for (int i = 0; i < items.Length; i += 2) { string type = items[i]; long amount = long.Parse(items[i + 1]); bag.Add(type, amount); } Console.WriteLine(bag.GetInfo()); }
public void Add(Bag bag) { if (itemName.Length == 3) { category = "Cash"; } else if (itemName.ToLower().EndsWith("gem")) { category = "Gem"; } else if (itemName.ToLower() == "gold") { category = "Gold"; } if (category == "" || maxCapacity < bag.GetBagSum() + quantity) { return; } switch (category) { case "Gem": if (!bag.Contains(category)) { if (bag.Contains("Gold")) { if (quantity > bag.GetCategory("Gold").GetSum()) { return; } } else { return; } } else if (bag.GetCategory(category).GetSum() + quantity > bag.GetCategory("Gold").GetSum()) { return; } break; case "Cash": if (!bag.Contains(category)) { if (bag.Contains("Gem")) { if (quantity > bag.GetCategory("Gem").GetSum()) { return; } } else { return; } } else if (bag.GetCategory(category).GetSum() + quantity > bag.GetCategory("Gem").GetSum()) { return; } break; } if (!bag.Contains(category)) { bag.Add(category); } if (!bag.GetCategory(category).Contains(itemName)) { bag.GetCategory(category).AddItem(itemName); bag.GetCategory(category).GetItem(itemName).Quantity = 0; } bag.GetCategory(category).GetItem(itemName).Quantity += quantity; }