bullit3189

Sport Cards

Jun 10th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _01SportCards
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, Dictionary<string, double>> cardNameSportPrice = new Dictionary<string, Dictionary<string, double>>();
  12.  
  13. while (true)
  14. {
  15. string command = Console.ReadLine();
  16.  
  17. if(command == "end")
  18. {
  19. break;
  20. }
  21.  
  22. if(!command.Contains("check"))
  23. {
  24. string[] tokens = command.Split(" - ");
  25. string cardName = tokens[0];
  26. string sport = tokens[1];
  27. double price = double.Parse(tokens[2]);
  28.  
  29. if(!cardNameSportPrice.ContainsKey(cardName))
  30. {
  31. cardNameSportPrice.Add(cardName, new Dictionary<string, double>());
  32. cardNameSportPrice[cardName].Add(sport, price);
  33. }
  34. else if (cardNameSportPrice.ContainsKey(cardName)==true && cardNameSportPrice[cardName].ContainsKey(sport)==false)
  35. {
  36. cardNameSportPrice[cardName].Add(sport, price);
  37. }
  38. else if (cardNameSportPrice.ContainsKey(cardName) == true && cardNameSportPrice[cardName].ContainsKey(sport) == true)
  39. {
  40. cardNameSportPrice[cardName][sport] = price;
  41. }
  42. }
  43. else
  44. {
  45. string[] tokens = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  46. string cardName = tokens[1];
  47. if(!cardNameSportPrice.ContainsKey(cardName))
  48. {
  49. Console.WriteLine($"{cardName} is not available!");
  50. }
  51. else
  52. {
  53. Console.WriteLine($"{cardName} is available!");
  54. }
  55. }
  56. }
  57.  
  58. foreach (var kvp in cardNameSportPrice.OrderByDescending(x=>x.Value.Keys.Count))
  59. {
  60. string card = kvp.Key;
  61.  
  62. Console.WriteLine($"{card}:");
  63.  
  64. foreach (var inner in kvp.Value.OrderBy(x=>x.Key))
  65. {
  66. Console.WriteLine($" -{inner.Key} - {inner.Value:f2}");
  67. }
  68. }
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment