static void Main(string[] args) { string input = Console.ReadLine(); Dictionary <string, List <Evolutions> > evolutionDict = new Dictionary <string, List <Evolutions> >(); while (input != "wubbalubbadubdub") { var inputArgs = input.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray(); if (inputArgs.Length > 1) { string pokemonName = inputArgs[0]; string evolutionType = inputArgs[1]; int index = int.Parse(inputArgs[2]); Evolutions newEvo = new Evolutions(); newEvo.EvolutionType = evolutionType; newEvo.EvolutionIndex = index; if (!evolutionDict.ContainsKey(pokemonName)) { evolutionDict[pokemonName] = new List <Evolutions>(); } evolutionDict[pokemonName].Add(newEvo); } else { string pokemonName = inputArgs[0]; if (evolutionDict.ContainsKey(pokemonName)) { Console.WriteLine($"# {pokemonName}"); foreach (var evolution in evolutionDict[pokemonName]) { Console.WriteLine($"{evolution.EvolutionType} <-> {evolution.EvolutionIndex}"); } } } input = Console.ReadLine(); } foreach (var name in evolutionDict) { Console.WriteLine($"# {name.Key}"); foreach (var evolution in name.Value.OrderByDescending(x => x.EvolutionIndex)) { Console.WriteLine($"{evolution.EvolutionType} <-> {evolution.EvolutionIndex}"); } } }
static void Main(string[] args) { var pokemons = new List <Pokemon>(); var line = Console.ReadLine(); var patternNewPokemon = @"(.+) -> (.+) -> (.+)"; while (line != "wubbalubbadubdub") { if (Regex.IsMatch(line, patternNewPokemon)) { MatchCollection matches = Regex.Matches(line, patternNewPokemon); var currentPokemon = new Pokemon(); currentPokemon.Name = matches[0].Groups[1].Value; var currentEvolution = new Evolutions(); currentEvolution.Type = matches[0].Groups[2].Value; currentEvolution.Index = int.Parse(matches[0].Groups[3].Value); var evolutions = new List <Evolutions>(); evolutions.Add(currentEvolution); currentPokemon.Evolutions = evolutions; if (pokemons.Any(x => x.Name == currentPokemon.Name) == false) { pokemons.Add(currentPokemon); } else { var pokemonFirst = pokemons.First(x => x.Name == currentPokemon.Name); pokemonFirst.Evolutions.Add(currentEvolution); } } else { if (pokemons.Any(x => x.Name == line)) { var pokemonFirst = pokemons.First(x => x.Name == line); Console.WriteLine($"# {pokemonFirst.Name}"); foreach (var evolution in pokemonFirst.Evolutions) { Console.WriteLine($"{evolution.Type} <-> {evolution.Index}"); } } } line = Console.ReadLine(); } foreach (var pokemon in pokemons) { Console.WriteLine($"# {pokemon.Name}"); foreach (var evolution in pokemon.Evolutions.OrderByDescending(x => x.Index))// without thenby { Console.WriteLine($"{evolution.Type} <-> {evolution.Index}"); } } }
static void Main(string[] args) { var input = Console.ReadLine(); var result = new Dictionary <string, List <Evolutions> >(); while (input != "wubbalubbadubdub") { var tokens = input.Split(" ->".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var pokeName = tokens[0]; if (tokens.Length > 1) { var pokeEvo = tokens[1]; var pokeIndex = int.Parse(tokens[2]); var newEvolution = new Evolutions(); newEvolution.EvoName = pokeEvo; newEvolution.EvoIndex = pokeIndex; if (!result.ContainsKey(pokeName)) { result[pokeName] = new List <Evolutions>(); } result[pokeName].Add(newEvolution); } else { if (result.ContainsKey(pokeName)) { Console.WriteLine($"# {pokeName}"); foreach (var evoluton in result[pokeName]) { Console.WriteLine($"{evoluton.EvoName} <-> {evoluton.EvoIndex}"); } } } input = Console.ReadLine(); } foreach (var name in result) { Console.WriteLine($"# {name.Key}"); foreach (var evoluton in name.Value.OrderByDescending(x => x.EvoIndex)) { Console.WriteLine($"{evoluton.EvoName} <-> {evoluton.EvoIndex}"); } } }