Guest User

PokemonEvolution

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