Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace More04SupermarketDatabase
- {
- class Program
- {
- static void Main()
- {
- // Judge decide 40/100 because row 40 is .Min() instead of .Last()!
- var products = Console.ReadLine();
- var result = new Dictionary<string, Dictionary<double, double>>();
- var totalAmount = 0.0;
- while (products != "stocked")
- {
- var product = products.Split().ToArray();
- var name = product[0];
- var price = double.Parse(product[1]);
- var quantity = double.Parse(product[2]);
- if (!result.ContainsKey(name))
- {
- result[name] = new Dictionary<double, double>();
- }
- if (!result[name].ContainsKey(price))
- {
- result[name][price] = 0;
- }
- result[name][price]+= quantity;
- products = Console.ReadLine();
- }
- foreach (var namePriceQuantity in result)
- {
- var name = namePriceQuantity.Key;
- var price = namePriceQuantity.Value.Keys.Min(); //var price = namePriceQuantity.Value.Keys.Last();
- var quantity = namePriceQuantity.Value.Values.Sum();
- totalAmount += (quantity * price);
- Console.WriteLine($"{name}: ${price:f2} * {quantity} = ${quantity * price:f2}");
- }
- Console.WriteLine("------------------------------");
- Console.WriteLine($"Grand Total: ${totalAmount:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement