Advertisement
Militsa

05. Pokemon Evolution

Dec 8th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class Evolutions
  8. {
  9.     public string EvoName { get; set; }
  10.     public int EvoIndex { get; set; }
  11.  
  12. }
  13.  
  14. namespace _05.Pokemon_Evolution
  15. {
  16.     class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             var input = Console.ReadLine();
  21.             var result = new Dictionary<string, List<Evolutions>>();
  22.  
  23.             while (input != "wubbalubbadubdub")
  24.             {
  25.                 var tokens = input.Split(" ->".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  26.                 var pokeName = tokens[0];
  27.                 if (tokens.Length > 1)
  28.                 {
  29.  
  30.                     var pokeEvo = tokens[1];
  31.                     var pokeIndex = int.Parse(tokens[2]);
  32.  
  33.                     var newEvolution = new Evolutions();
  34.                     newEvolution.EvoName = pokeEvo;
  35.                     newEvolution.EvoIndex = pokeIndex;
  36.  
  37.                     if (!result.ContainsKey(pokeName))
  38.                     {
  39.                         result[pokeName] = new List<Evolutions>();
  40.                     }
  41.                     result[pokeName].Add(newEvolution);
  42.                 }
  43.                 else
  44.                 {
  45.  
  46.                     if (result.ContainsKey(pokeName))
  47.                     {
  48.                         Console.WriteLine("# {0}",pokeName);
  49.                         foreach (var evoluton in result[pokeName])
  50.                         {
  51.                             Console.WriteLine("{0} <-> {1}",evoluton.EvoName,evoluton.EvoIndex);
  52.                         }
  53.                     }
  54.                 }
  55.  
  56.                 input = Console.ReadLine();
  57.             }
  58.  
  59.             foreach (var name in result)
  60.             {
  61.                 Console.WriteLine("# {0}", name.Key);
  62.                 foreach (var evoluton in name.Value.OrderByDescending(x => x.EvoIndex))
  63.                 {
  64.                     Console.WriteLine("{0} <-> {1}", evoluton.EvoName, evoluton.EvoIndex);
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement