Advertisement
Guest User

Another Pokemon Evolution

a guest
Sep 2nd, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _04.PokemonEvolution
  8. {
  9. class PokemonEvolution
  10. {
  11. static void Main(string[] args)
  12. {
  13. var dictionary = new Dictionary<string, Dictionary<string, List<long>>>();
  14.  
  15. var input = Console.ReadLine();
  16.  
  17. while (input != "wubbalubbadubdub")
  18. {
  19. var inputArgs = input.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  20. var pokemon = inputArgs[0];
  21.  
  22. if (inputArgs.Length>1)
  23. {
  24. var evolutionType = inputArgs[1];
  25. var evolutionIndex = long.Parse(inputArgs[2]);
  26.  
  27. if (!dictionary.ContainsKey(pokemon))
  28. {
  29. dictionary.Add(pokemon, new Dictionary<string, List<long>>());
  30. }
  31.  
  32. if (!dictionary[pokemon].ContainsKey(evolutionType))
  33. {
  34. dictionary[pokemon].Add(evolutionType, new List<long>());
  35. }
  36.  
  37. dictionary[pokemon][evolutionType].Add(evolutionIndex);
  38. }
  39.  
  40. else
  41. {
  42. // not working.... ;(
  43.  
  44. if (dictionary.ContainsKey(pokemon))
  45. {
  46. Console.WriteLine($"# {pokemon}");
  47.  
  48. foreach (var kvp in dictionary.Where(x=>x.Key==pokemon))
  49. {
  50. foreach (var innerKvp in kvp.Value)
  51. {
  52. foreach (var item in innerKvp.Value)
  53. {
  54. Console.WriteLine($"{innerKvp.Key} -> {item}");
  55. }
  56. }
  57. }
  58.  
  59.  
  60. }
  61. }
  62.  
  63. input = Console.ReadLine();
  64. }
  65.  
  66. // the final printing is working
  67.  
  68. foreach (var kvp in dictionary)
  69. {
  70. Console.WriteLine($"# {kvp.Key}");
  71.  
  72. foreach (var innerKvp in kvp.Value)
  73. {
  74. foreach (var listItem in innerKvp.Value.OrderByDescending(x=>x))
  75. {
  76. Console.WriteLine($"{innerKvp.Key} -> {listItem}");
  77. }
  78.  
  79. }
  80. }
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement