miroslavbstoyanov

Untitled

Nov 1st, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 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.Pokemon_Evolution
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string input = "";
  14. List<PokemonEvolution> listOfPokemons = new List<PokemonEvolution>();
  15.  
  16. while ((input = Console.ReadLine()) != "wubbalubbadubdub")
  17. {
  18. if (listOfPokemons.Select(x => x.Name).Contains(input))
  19. {
  20. printPokemon(input, listOfPokemons);
  21. continue;
  22. }
  23. string[] slitedInput = input.Split(new string[] { " ", "-", ">" }, StringSplitOptions.RemoveEmptyEntries);
  24. if (slitedInput.Length != 3)
  25. {
  26. continue;
  27. }
  28. PokemonEvolution pokemons = new PokemonEvolution();
  29. pokemons.Name = slitedInput[0];
  30. if (!listOfPokemons.Select(x => x.Name).Contains(slitedInput[0]))
  31. {
  32. pokemons.Name = slitedInput[0];
  33. pokemons.Evolution = new List<string>();
  34. pokemons.Index = new List<int>();
  35. pokemons.Evolution.Add(slitedInput[1]);
  36. pokemons.Index.Add(int.Parse(slitedInput[2]));
  37. listOfPokemons.Add(pokemons);
  38. }
  39. else
  40. {
  41. for (int i = 0; i < listOfPokemons.Count; i++)
  42. {
  43. if (listOfPokemons[i].Name == slitedInput[0])
  44. {
  45. listOfPokemons[i].Evolution.Add(slitedInput[1]);
  46. listOfPokemons[i].Index.Add(int.Parse(slitedInput[2]));
  47. }
  48.  
  49.  
  50. }
  51. }
  52. }
  53.  
  54. foreach (var item in listOfPokemons)
  55. {
  56. Console.WriteLine($"# {item.Name}");
  57.  
  58. //item.Evolution = item.Evolution.OrderBy(x => item.Index.IndexOf(y)).ToList();
  59.  
  60.  
  61. item.Index = item.Index.OrderByDescending(x => x).ToList();
  62.  
  63. for (int i = 0; i < item.Index.Count; i++)
  64. {
  65. Console.WriteLine("{0} <-> {1}", item.Evolution[i], item.Index[i]);
  66. }
  67. }
  68.  
  69. }
  70.  
  71. private static void printPokemon(string input, List<PokemonEvolution> listOfPokemons)
  72. {
  73. foreach (var item in listOfPokemons.Where(x => x.Name == input))
  74. {
  75. Console.WriteLine(item.Name);
  76.  
  77. for (int i = 0; i < item.Index.Count; i++)
  78. {
  79. Console.WriteLine("{0} <-> {1}", item.Evolution[i], item.Index[i]);
  80. }
  81. }
  82. }
  83.  
  84.  
  85. }
  86. class PokemonEvolution
  87. {
  88. public string Name { get; set; }
  89. public List<string> Evolution { get; set; }
  90. public List<int> Index { get; set; }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment