petyaminkova91

Untitled

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