MiroslavKisov

PokemonEvolution

Dec 5th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _05.PokemonEvolution
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             var pokemons = new Dictionary<string, List<KeyValuePair<string, long>>>();
  12.             while (true)
  13.             {
  14.                 string input = Console.ReadLine();
  15.                 if (input == "wubbalubbadubdub")
  16.                 {
  17.                     break;
  18.                 }
  19.                 var commandArgs = input
  20.                     .Split(new char[] { ' ', '>', '-' }, StringSplitOptions.RemoveEmptyEntries)
  21.                     .ToArray();
  22.                 if (commandArgs.Length == 3)
  23.                 {
  24.                     string pokemonName = commandArgs[0];
  25.                     string evolutionType = commandArgs[1];
  26.                     long evolutionIndex = long.Parse(commandArgs[2]);
  27.                     if (!pokemons.ContainsKey(pokemonName))
  28.                     {
  29.                         pokemons.Add(pokemonName, new List<KeyValuePair<string, long>>());
  30.                         pokemons[pokemonName].Add(new KeyValuePair<string, long>(evolutionType, evolutionIndex));
  31.                     }
  32.                     else
  33.                     {
  34.                         pokemons[pokemonName].Add(new KeyValuePair<string, long>(evolutionType, evolutionIndex));
  35.                     }
  36.                 }
  37.                 else
  38.                 {
  39.                     string pokemonName = commandArgs[0];
  40.                     if (pokemons.ContainsKey(pokemonName))
  41.                     {
  42.                         Console.WriteLine($"# {pokemonName}");
  43.                         foreach (var pokemon in pokemons[pokemonName])
  44.                         {
  45.                             Console.WriteLine($"{pokemon.Key} <-> {pokemon.Value}");
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.             foreach (var pokemon in pokemons)
  51.             {
  52.                 Console.WriteLine($"# {pokemon.Key}");
  53.                 foreach (var item in pokemon.Value.OrderByDescending(x=>x.Value))
  54.                 {
  55.                     Console.WriteLine($"{item.Key} <-> {item.Value}");
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment