Guest User

Orders

a guest
Nov 12th, 2019
197
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. }
  29. else if(product != "buy")
  30. {
  31. double price = double.Parse(input[1]);
  32. int quantity = int.Parse(input[2]);
  33. double PriceforAll = price * quantity;
  34. totalQuantity.Add(product, quantity);
  35. totalPrice.Add(product, PriceforAll);
  36. }
  37.  
  38. if(product =="buy")
  39. {
  40. foreach (var p in totalPrice)
  41. {
  42. Console.WriteLine($"{p.Key} -> {p.Value:f2}");
  43. }
  44. break;
  45. }
  46.  
  47. }
  48. }
  49. }
  50. }
RAW Paste Data