static void Main() { //input int ingrCount = int.Parse(Console.ReadLine()); Dictionary <string, Ingred> allOfIngridients = new Dictionary <string, Ingred>(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < ingrCount; i++) { string[] item = Console.ReadLine().Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (allOfIngridients.ContainsKey(item[2])) { allOfIngridients[item[2]].quantity = allOfIngridients[item[2]].quantity + (decimal.Parse(item[0]) * (ConvertMeasurment(item[1], allOfIngridients[item[2]].measurment))); } else { Ingred temp = new Ingred(); temp.measurment = item[1]; temp.quantity = decimal.Parse(item[0]); allOfIngridients.Add(item[2], temp); } } int putIn = int.Parse(Console.ReadLine()); for (int i = 0; i < putIn; i++) { string[] item = Console.ReadLine().Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (allOfIngridients.ContainsKey(item[2])) { allOfIngridients[item[2]].quantity = allOfIngridients[item[2]].quantity - (decimal.Parse(item[0]) * (ConvertMeasurment(item[1], allOfIngridients[item[2]].measurment))); } } foreach (var item in allOfIngridients) { if (item.Value.quantity > 0) { Console.WriteLine("{0:0.00}:{1}:{2}", item.Value.quantity, item.Value.measurment, item.Key); } } }
static void Main() { //input int ingrCount = int.Parse(Console.ReadLine()); Dictionary<string, Ingred> allOfIngridients = new Dictionary<string, Ingred>(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < ingrCount; i++) { string[] item = Console.ReadLine().Split(new char[]{':'},StringSplitOptions.RemoveEmptyEntries); if (allOfIngridients.ContainsKey(item[2])) { allOfIngridients[item[2]].quantity = allOfIngridients[item[2]].quantity + (decimal.Parse(item[0]) * (ConvertMeasurment(item[1], allOfIngridients[item[2]].measurment))); } else { Ingred temp = new Ingred(); temp.measurment = item[1]; temp.quantity = decimal.Parse(item[0]); allOfIngridients.Add(item[2], temp); } } int putIn = int.Parse(Console.ReadLine()); for (int i = 0; i < putIn; i++) { string[] item = Console.ReadLine().Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (allOfIngridients.ContainsKey(item[2])) { allOfIngridients[item[2]].quantity = allOfIngridients[item[2]].quantity - (decimal.Parse(item[0]) * (ConvertMeasurment(item[1], allOfIngridients[item[2]].measurment))); } } foreach (var item in allOfIngridients) { if (item.Value.quantity > 0) { Console.WriteLine("{0:0.00}:{1}:{2}",item.Value.quantity,item.Value.measurment,item.Key); } } }