Advertisement
petyaminkova91

Untitled

Nov 12th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 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. foreach (var product in products)
  29. {
  30. if (product.Key == currentProduct)
  31. {
  32. product.Value[0] = priceForOneProduct;
  33. product.Value[1] += quantity;
  34. }
  35. }
  36. }
  37.  
  38. input = Console.ReadLine();
  39. }
  40.  
  41. foreach (var product in products)
  42. {
  43. product.Value[0] = product.Value[0] * product.Value[1];
  44.  
  45. Console.WriteLine($"{product.Key} -> {product.Value[0]:f2}");
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement