Guest User

Orders

a guest
Nov 24th, 2019
359
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  27. totalPrice[product] = (totalQuantity[product] + quantity) * price;
  28. totalQuantity[product] += quantity;
  29. }
  30. else if(product != "buy")
  31. {
  32. double price = double.Parse(input[1]);
  33. int quantity = int.Parse(input[2]);
  34. double PriceforAll = price * quantity;
  35. totalQuantity.Add(product, quantity);
  36. totalPrice.Add(product, PriceforAll);
  37. }
  38.  
  39. if(product =="buy")
  40. {
  41. foreach (var p in totalPrice)
  42. {
  43. Console.WriteLine($"{p.Key} -> {p.Value:f2}");
  44. }
  45. break;
  46. }
  47.  
  48. }
  49. }
  50. }
  51. }
RAW Paste Data