private static void AddPokemonInfo(List <Pokemon> pokemons, string[] tokens) { string pokemonName = tokens[0]; string evolutionType = tokens[1]; int evolutionIndex = Convert.ToInt32(tokens[2]); evolutionType = tokens[1]; evolutionIndex = Convert.ToInt32(tokens[2]); if (!pokemons.Exists(p => p.Name.Equals(pokemonName))) { Pokemon newPokemon = new Pokemon { Name = pokemonName, Evolutions = new List <Evolution> { } }; pokemons.Add(newPokemon); } Pokemon pokemon = pokemons.Where(p => p.Name.Equals(pokemonName)).First(); Evolution evolution = new Evolution { EvolutionType = evolutionType, EvolutionIndex = evolutionIndex }; pokemon.Evolutions.Add(evolution); }
static void Main() { Dictionary <string, List <Evolution> > pokemonz = new Dictionary <string, List <Evolution> >(); string input = string.Empty; while ((input = Console.ReadLine()) != "wubbalubbadubdub") { string[] args = input.Split(new[] { ' ', '-', '>' }, StringSplitOptions.RemoveEmptyEntries); string name = args[0]; if (args.Length == 1) { if (pokemonz.ContainsKey(name)) { foreach (var pokemon in pokemonz.Where(x => x.Key == name)) { Console.WriteLine($"# {pokemon.Key}"); foreach (var item in pokemon.Value) { Console.WriteLine($"{item.EvoType} <-> {item.EvoIndex}"); } } } } else { string evoType = args[1]; int evoIndex = int.Parse(args[2]); if (!pokemonz.ContainsKey(name)) { pokemonz.Add(name, new List <Evolution>()); } Evolution newEvo = new Evolution { EvoIndex = evoIndex, EvoType = evoType }; pokemonz[name].Add(newEvo); } } foreach (var poke in pokemonz) { Console.WriteLine($"# {poke.Key}"); foreach (var item in poke.Value.OrderByDescending(x => x.EvoIndex)) { Console.WriteLine($"{item.EvoType} <-> {item.EvoIndex}"); } } }
static void Main(string[] args) { string input = Console.ReadLine(); string pattern = @"(.+) -> (.+) -> (.+)"; var pokemons = new Dictionary <string, List <Evolution> >(); while (input != "wubbalubbadubdub") { if (Regex.IsMatch(input, pattern)) { Match m = Regex.Match(input, pattern); Evolution e = new Evolution(); e.Type = m.Groups[2].Value; e.Index = long.Parse(m.Groups[3].Value); string name = m.Groups[1].Value; if (!pokemons.ContainsKey(name)) { pokemons.Add(name, new List <Evolution>()); } pokemons[name].Add(e); } else { string name = input; if (pokemons.ContainsKey(name)) { Console.WriteLine($"# {name}"); foreach (var e in pokemons[name]) { Console.WriteLine($"{e.Type} <-> {e.Index}"); } } } input = Console.ReadLine(); } foreach (var p in pokemons) { Console.WriteLine($"# {p.Key}"); foreach (var e in pokemons[p.Key].OrderByDescending(ev => ev.Index)) { Console.WriteLine($"{e.Type} <-> {e.Index}"); } } }// 78492
private static void AddPokemonInfo(string name, string evolution, int index, List <Pokemon> pokemons) { if (!pokemons.Exists(p => p.Name == name)) { Pokemon newPokemon = new Pokemon { Name = name, Evolutions = new List <Evolution>() }; pokemons.Add(newPokemon); } Evolution currentEvolution = new Evolution { EvolutionType = evolution, EvolutionIndex = index }; Pokemon currentPokemon = pokemons.Where(p => p.Name == name).First(); currentPokemon.Evolutions.Add(currentEvolution); }
static void Main(string[] args) { List <Pokemon> pokemons = new List <Pokemon>(); string input = Console.ReadLine(); while (input != "wubbalubbadubdub") { if (input.Contains("->")) { string[] data = input.Split(new char[] { ' ', '-', '>' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); string name = data[0]; string type = data[1]; int index = int.Parse(data[2]); if (pokemons.Any(x => x.Name == name)) { Pokemon temp = pokemons.Where(x => x.Name == name).First(); if (temp.Evolutions == null) { temp.Evolutions = new List <Evolution>(); } Evolution temporary = new Evolution(); temporary.Type = type; temporary.Index = index; temp.Evolutions.Add(temporary); } else { Pokemon temp = new Pokemon(); temp.Name = name; temp.Evolutions = new List <Evolution>(); Evolution temporary = new Evolution(); temporary.Type = type; temporary.Index = index; temp.Evolutions.Add(temporary); pokemons.Add(temp); } } else { string name = input; if (pokemons.Any(x => x.Name == name)) { Pokemon temp = pokemons.Where(x => x.Name == name).First(); Console.WriteLine("# {0}", name); foreach (var evolution in temp.Evolutions) { Console.WriteLine("{0} <-> {1}", evolution.Type, evolution.Index); } } } input = Console.ReadLine(); } foreach (var pokemon in pokemons) { pokemon.Evolutions = pokemon.Evolutions.OrderByDescending(x => x.Index).ToList(); Console.WriteLine("# {0}", pokemon.Name); foreach (var evolution in pokemon.Evolutions) { Console.WriteLine("{0} <-> {1}", evolution.Type, evolution.Index); } } }
static void Main() { Dictionary <string, List <Evolution> > pokeEvoDict = new Dictionary <string, List <Evolution> >(); var input = Console.ReadLine() .Split(new[] { '-', ' ', '>' }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); string pokeName = ""; while (input[0] != "wubbalubbadubdub") { if (input.Length > 1) { Evolution evolution = new Evolution(); pokeName = input[0]; evolution.Type = input[1]; evolution.Index = int.Parse(input[2]); if (!pokeEvoDict.ContainsKey(pokeName)) { List <Evolution> listEvo = new List <Evolution>() { evolution }; pokeEvoDict.Add(pokeName, listEvo); } else { pokeEvoDict[pokeName].Add(evolution); } } else { pokeName = input[0]; if (pokeEvoDict.ContainsKey(pokeName)) { Console.WriteLine($"# {pokeName}"); foreach (var ev in pokeEvoDict[pokeName]) { Console.WriteLine($"{ev.Type} <-> {ev.Index}"); } } } input = Console.ReadLine() .Split(new[] { '-', ' ', '>' }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); } foreach (var kvp in pokeEvoDict) { Console.WriteLine($"# {kvp.Key}"); foreach (var ev in kvp.Value.OrderByDescending(x => x.Index)) { Console.WriteLine($"{ev.Type} <-> {ev.Index}"); } } //============================================================================================================= //var input = Console.ReadLine() // .Split(new[] { '-', ' ', '>' }, StringSplitOptions.RemoveEmptyEntries) // .ToArray(); //string pokeName = ""; //string evolution = ""; //Dictionary<string, List<string>> pokemons = new Dictionary<string, List<string>>(); //while (input[0] != "wubbalubbadubdub") //{ // if (input.Length > 1) // { // pokeName = input[0]; // evolution = input[1] + " <-> " + input[2]; // if (!pokemons.ContainsKey(pokeName)) // { // List<string> currentList = new List<string>() { evolution }; // pokemons.Add(pokeName, currentList); // } // else // { // pokemons[pokeName].Add(evolution); // } // } // else // { // pokeName = input[0]; // if (pokemons.ContainsKey(pokeName)) // { // Console.WriteLine($"# {pokeName}"); // foreach (var ev in pokemons[pokeName]) // { // Console.WriteLine($"{ev}"); // } // } // } // input = Console.ReadLine() // .Split(new[] { '-', ' ', '>' }, StringSplitOptions.RemoveEmptyEntries) // .ToArray(); //} //foreach (var kvp in pokemons) //{ // Console.WriteLine($"# {kvp.Key}"); // foreach (var ev in kvp.Value. // OrderByDescending(x => int.Parse(x.Split(new[] { '<', '-', ' ', '>' }, StringSplitOptions.RemoveEmptyEntries) // .Skip(1) // .First()))) // { // Console.WriteLine($"{ev}"); // } //} }