Esempio n. 1
0
        static void Main(string[] args)
        {
            var pokemons = new Dictionary <string, List <Evolution> >();

            string[] input = Console.ReadLine().Split(new char[]
                                                      { '-', '>', ' ' }, StringSplitOptions
                                                      .RemoveEmptyEntries)
                             .ToArray();
            var name = "";

            while (input[0] != "wubbalubbadubdub")
            {
                if (input.Length > 1)
                {
                    Evolution evolution = new Evolution();
                    evolution.Type  = input[1];
                    evolution.Power = int.Parse(input[2]);
                    name            = input[0];

                    if (!pokemons.ContainsKey(name))
                    {
                        var currentList = new List <Evolution>()
                        {
                            evolution
                        };
                        pokemons.Add(name, currentList);
                    }
                    else
                    {
                        pokemons[name].Add(evolution);
                    }
                }
                else
                {
                    name = input[0];
                    if (pokemons.ContainsKey(name))
                    {
                        Console.WriteLine($"# {name}");
                        foreach (var ev in pokemons[name])
                        {
                            Console.WriteLine($"{ev.Type} <-> {ev.Power}");
                        }
                    }
                }

                input = Console.ReadLine().Split(new char[]
                                                 { '-', '>', ' ' }, StringSplitOptions
                                                 .RemoveEmptyEntries)
                        .ToArray();
            }

            foreach (var pair in pokemons)
            {
                Console.WriteLine($"# {pair.Key}");
                foreach (var ev in pair.Value.OrderByDescending(x => x.Power))
                {
                    Console.WriteLine($"{ev.Type} <-> {ev.Power}");
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var            input    = Console.ReadLine();
            List <Pokemon> pokemons = new List <Pokemon>();

            while (input != "wubbalubbadubdub")
            {
                var currentPokemon = input.Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries)
                                     .ToList();

                Pokemon pokemon = new Pokemon();

                if (currentPokemon.Count == 1)
                {
                    pokemon = pokemons.First(x => x.Name == currentPokemon[0].Trim());
                    Console.WriteLine($"# {pokemon.Name}");

                    foreach (var evol in pokemon.Evolutions)
                    {
                        Console.WriteLine($"{evol.EvolutionName} <-> {evol.Index}");
                    }
                    input = Console.ReadLine();

                    continue;
                }
                pokemon.Name = currentPokemon[0].Trim();
                List <Evolution> evolutions       = new List <Evolution>();
                Evolution        currentEvolution = new Evolution();

                currentEvolution.EvolutionName = currentPokemon[1].Trim();
                currentEvolution.Index         = int.Parse(currentPokemon[2].Trim());

                if (pokemons.Any(x => x.Name == currentPokemon[0].Trim()))
                {
                    pokemon = pokemons.First(y => y.Name == currentPokemon[0].Trim());
                    pokemon.Evolutions.Add(currentEvolution);
                }
                else
                {
                    evolutions.Add(currentEvolution);
                    pokemon.Evolutions = evolutions;
                    pokemons.Add(pokemon);
                }
                input = Console.ReadLine();
            }

            foreach (var pokemon in pokemons)
            {
                Console.WriteLine($"# {pokemon.Name}");

                foreach (var evol in pokemon.Evolutions.OrderByDescending(x => x.Index))
                {
                    Console.WriteLine($"{evol.EvolutionName} <-> {evol.Index}");
                }
            }
        }