Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _04._Orders
- {
- class Program
- {
- static void Main(string[] args)
- {
- var productsCatalogue = new Dictionary<string, List<double>>();
- string command = Console.ReadLine();
- while (command != "buy")
- {
- var priceAndQuantity = new List<double>();
- string productName = string.Empty;
- var productInfo = command
- .Split()
- .ToArray();
- productName = productInfo[0];
- priceAndQuantity.Add(double.Parse(productInfo[1]));
- priceAndQuantity.Add(int.Parse(productInfo[2]));
- if (!productsCatalogue.ContainsKey(productName))
- productsCatalogue.Add(productName, priceAndQuantity);
- else
- {
- productsCatalogue[productName][1] += priceAndQuantity[1];
- productsCatalogue[productName][0] = priceAndQuantity[0];
- }
- command = Console.ReadLine();
- }
- foreach (var item in productsCatalogue)
- {
- double price = item.Value[0];
- double quantity = item.Value[1];
- double totalPrice = price * quantity;
- Console.WriteLine($"{item.Key} -> {totalPrice:F2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement