Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Orders
- {
- class Program
- {
- public static void Main()
- {
- Dictionary<string, double> productsAndPrices = new Dictionary<string, double>();
- Dictionary<string, int> ordersQuantity = new Dictionary<string, int>();
- string command;
- while ((command = Console.ReadLine()) != "buy")
- {
- string[] currentOrder = command.Split(" ");
- string product = currentOrder[0];
- double price = double.Parse(currentOrder[1]);
- int quantity = int.Parse(currentOrder[2]);
- if (!productsAndPrices.ContainsKey(product))
- {
- productsAndPrices.Add(product, 0);
- ordersQuantity.Add(product, 0);
- }
- productsAndPrices[product] = price;
- ordersQuantity[product] += quantity;
- }
- foreach (var order in ordersQuantity)
- {
- double orderPrice = productsAndPrices[order.Key] * order.Value;
- Console.WriteLine($"{order.Key} -> {orderPrice:f2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement