Advertisement
Guest User

Pokemon Evolution

a guest
Sep 1st, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 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.PokemonEvolutionWithClass
  8. {
  9. public class PokemonEvolutionWithClass
  10. {
  11. public static void Main()
  12. {
  13. var input = Console.ReadLine();
  14. var pokemons = new List<Pokemon>();
  15.  
  16. while (input != "wubbalubbadubdub")
  17. {
  18. var inputArgs = input.Split(new[] {" -> "}, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20. if (inputArgs.Length == 1)
  21. {
  22. var currentName = inputArgs[0];
  23.  
  24. var currentPokemon = pokemons.Where(x => x.Name == currentName).FirstOrDefault();
  25.  
  26. if (currentPokemon != null)
  27. {
  28. Console.WriteLine($"# {currentName}");
  29.  
  30. foreach (var pokemon in pokemons.Where(x => x.Name == currentName))
  31. {
  32. Console.WriteLine($"{pokemon.EnvironmentType} <-> {pokemon.Id}");
  33. }
  34. }
  35. }
  36.  
  37. else
  38. {
  39. var name = inputArgs[0];
  40. var environmentType = inputArgs[1];
  41. var id = long.Parse(inputArgs[2]);
  42.  
  43. var currentPokemon = new Pokemon(name, environmentType, id);
  44. pokemons.Add(currentPokemon);
  45. }
  46.  
  47. input = Console.ReadLine();
  48. }
  49.  
  50. foreach (var pokemonName in pokemons.Select(x => x.Name).Distinct())
  51. {
  52. Console.WriteLine($"# {pokemonName}");
  53.  
  54. foreach (var pokemon in pokemons.Where(x => x.Name == pokemonName).OrderByDescending(x => x.Id))
  55. {
  56. Console.WriteLine($"{pokemon.EnvironmentType} <-> {pokemon.Id}");
  57. }
  58. }
  59. }
  60. }
  61.  
  62. public class Pokemon
  63. {
  64. public string Name { get; set; }
  65. public string EnvironmentType { get; set; }
  66. public long Id { get; set; }
  67.  
  68. public Pokemon(string name, string environmentType, long id)
  69. {
  70. this.Name = name;
  71. this.EnvironmentType = environmentType;
  72. this.Id = id;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement