deleriumbg

Pokemon Evolution

Jun 26th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Pokemon_Evolution
  6. {
  7.     class Pokemon
  8.     {
  9.         public string Name { get; set; }
  10.         public List<Tuple<string, int>> EvolutionTypeAndIndex { get; set; }
  11.     }
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             string input = Console.ReadLine();
  17.             List<Pokemon> pokemons = new List<Pokemon>();
  18.  
  19.             while (input != "wubbalubbadubdub")
  20.             {
  21.                 string[] pokemonInfo = input.Split(new[] {'-', '>', ' '}, StringSplitOptions.RemoveEmptyEntries);
  22.                 if (pokemonInfo.Length == 3)
  23.                 {
  24.                     string pokemonName = pokemonInfo[0];
  25.                     string evolutionType = pokemonInfo[1];
  26.                     int evolutionIndex = int.Parse(pokemonInfo[2]);
  27.  
  28.                     Pokemon pokemon = new Pokemon();
  29.                     if (pokemons.All(x => x.Name != pokemonName))
  30.                     {
  31.                         pokemon.Name = pokemonName;
  32.                         pokemon.EvolutionTypeAndIndex = new List<Tuple<string, int>>();
  33.                         pokemon.EvolutionTypeAndIndex.Add(new Tuple<string, int>(evolutionType, evolutionIndex));
  34.                         pokemons.Add(pokemon);
  35.                     }
  36.                     else
  37.                     {
  38.                         Pokemon existingPokemon = pokemons.First(x => x.Name == pokemonName);
  39.                         existingPokemon.EvolutionTypeAndIndex.Add(new Tuple<string, int>(evolutionType, evolutionIndex));
  40.                     }
  41.                 }
  42.                 else if (pokemonInfo.Length == 1)
  43.                 {
  44.                     string pokemonName = pokemonInfo[0];
  45.                     if (pokemons.Any(x => x.Name == pokemonName))
  46.                     {
  47.                         Pokemon currentPokemon = pokemons.First(x => x.Name == pokemonName);
  48.                         Console.WriteLine($"# {currentPokemon.Name}");
  49.                         foreach (var typeIndexPair in currentPokemon.EvolutionTypeAndIndex)
  50.                         {
  51.                             Console.WriteLine($"{typeIndexPair.Item1} <-> {typeIndexPair.Item2}");
  52.                         }
  53.                     }
  54.                 }
  55.                 input = Console.ReadLine();
  56.             }
  57.  
  58.             foreach (var pokemon in pokemons)
  59.             {
  60.                 Console.WriteLine($"# {pokemon.Name}");
  61.                 foreach (var typeIndexPair in pokemon.EvolutionTypeAndIndex.OrderByDescending(x => x.Item2))
  62.                 {
  63.                     Console.WriteLine($"{typeIndexPair.Item1} <-> {typeIndexPair.Item2}");
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment