Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _04._Orders
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var productsCatalogue = new Dictionary<string, List<double>>();
  12. string command = Console.ReadLine();
  13.  
  14. while (command != "buy")
  15. {
  16. var priceAndQuantity = new List<double>();
  17. string productName = string.Empty;
  18. var productInfo = command
  19. .Split()
  20. .ToArray();
  21.  
  22. productName = productInfo[0];
  23. priceAndQuantity.Add(double.Parse(productInfo[1]));
  24. priceAndQuantity.Add(int.Parse(productInfo[2]));
  25.  
  26. if (!productsCatalogue.ContainsKey(productName))
  27. productsCatalogue.Add(productName, priceAndQuantity);
  28. else
  29. {
  30. productsCatalogue[productName][1] += priceAndQuantity[1];
  31. productsCatalogue[productName][0] = priceAndQuantity[0];
  32. }
  33.  
  34. command = Console.ReadLine();
  35. }
  36.  
  37. foreach (var item in productsCatalogue)
  38. {
  39. double price = item.Value[0];
  40. double quantity = item.Value[1];
  41. double totalPrice = price * quantity;
  42.  
  43. Console.WriteLine($"{item.Key} -> {totalPrice:F2}");
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement