Advertisement
Guest User

Orders2

a guest
Nov 12th, 2019
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Orders
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, double> totalPrice = new Dictionary<string, double>();
  12. Dictionary<string, int> totalQuantity = new Dictionary<string, int>();
  13.  
  14. while (true)
  15. {
  16. string[] input = Console.ReadLine()
  17. .Split();
  18.  
  19. string product = input[0];
  20.  
  21. if(totalPrice.ContainsKey(product) && product != "buy")
  22. {
  23. double price = double.Parse(input[1]);
  24. int quantity = int.Parse(input[2]);
  25.  
  26. totalPrice[product] = price;
  27. totalQuantity[product] += quantity;
  28. }
  29.  
  30. else if(product != "buy")
  31. {
  32. double price = double.Parse(input[1]);
  33. int quantity = int.Parse(input[2]);
  34.  
  35. totalQuantity.Add(product, quantity);
  36. totalPrice.Add(product, price);
  37. }
  38.  
  39. else if(product =="buy")
  40. {
  41. foreach (var p in totalQuantity)
  42. {
  43. string Product = p.Key;
  44. int quantity = p.Value;
  45. double price = totalPrice[Product];
  46. double results = quantity * price;
  47. Console.WriteLine($"{Product} -> {results:f2}");
  48. }
  49. break;
  50. }
  51.  
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement