Guest User

PokemonEvolution

a guest
Aug 3rd, 2017
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Evolutions
  6. {
  7.     public string EvoName { get; set; }
  8.     public int EvoIndex { get; set; }
  9.  
  10. }
  11.  
  12. namespace AppendLists
  13. {
  14.  
  15.     public class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  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($"# {pokeName}");
  49.                         foreach (var evoluton in result[pokeName])
  50.                         {
  51.                             Console.WriteLine($"{evoluton.EvoName} <-> {evoluton.EvoIndex}");
  52.                         }
  53.                     }
  54.                 }
  55.  
  56.  
  57.                 input = Console.ReadLine();
  58.             }
  59.  
  60.             foreach (var name in result)
  61.             {
  62.                 Console.WriteLine($"# {name.Key}");
  63.                 foreach (var evoluton in name.Value.OrderByDescending(x => x.EvoIndex))
  64.                 {
  65.                     Console.WriteLine($"{evoluton.EvoName} <-> {evoluton.EvoIndex}");
  66.                 }
  67.             }
  68.  
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment