static void Main()
        {
            string input = Console.ReadLine();

            var pokemons = new Dictionary <string, List <Evolution> >();

            while (input != "wubbalubbadubdub")
            {
                var line = input.Split("-> ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                if (line.Length == 1)
                {
                    if (pokemons.ContainsKey(line[0]))
                    {
                        foreach (var pokemon in pokemons)
                        {
                            if (pokemon.Key == line[0])
                            {
                                Console.WriteLine("# " + pokemon.Key);
                                pokemon.Value
                                .ToList()
                                .ForEach(x => Console.WriteLine($"{x.EvolutionType} <-> {x.Index}"));
                            }
                        }
                    }

                    input = Console.ReadLine();
                    continue;
                }

                if (!pokemons.ContainsKey(line[0]))
                {
                    pokemons[line[0]] = new List <Evolution>();
                }



                var temp = new Evolution
                {
                    EvolutionType = line[1],
                    Index         = long.Parse(line[2])
                };

                pokemons[line[0]].Add(temp);
                input = Console.ReadLine();
            }

            foreach (var evolutions in pokemons)
            {
                Console.WriteLine($"# {evolutions.Key}");
                evolutions.Value
                .OrderByDescending(x => x.Index)
                .ToList()
                .ForEach(x => Console.WriteLine($"{x.EvolutionType} <-> {x.Index}"));
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            string command  = Console.ReadLine();
            var    pokemons = new Dictionary <string, List <Evolution> >();

            while (command != "wubbalubbadubdub")
            {
                var    tokens      = command.Split(" ->".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string pokemonName = tokens[0];
                if (tokens.Length > 1)
                {
                    Evolution evolution = new Evolution
                    {
                        EvolutionType  = tokens[1],
                        EvolutionIndex = long.Parse(tokens[2]),
                    };

                    if (!pokemons.ContainsKey(pokemonName))
                    {
                        pokemons[pokemonName] = new List <Evolution>();
                    }
                    pokemons[pokemonName].Add(evolution);
                }
                else
                {
                    if (pokemons.ContainsKey(pokemonName))
                    {
                        Console.WriteLine($"# {pokemonName}");

                        foreach (var pokemon in pokemons[pokemonName])
                        {
                            Console.WriteLine($"{pokemon.EvolutionType} <-> {pokemon.EvolutionIndex}");
                        }
                    }
                }
                command = Console.ReadLine();
            }
            foreach (var pokemon in pokemons)
            {
                Console.WriteLine($"# {pokemon.Key}");
                foreach (var poke in pokemon.Value.OrderByDescending(p => p.EvolutionIndex))
                {
                    Console.WriteLine($"{poke.EvolutionType} <-> {poke.EvolutionIndex}");
                }
            }
        }