emilia98

Pokemon Evolution - GROUP

Aug 16th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace PokemonEvolution
  6. {
  7.     class PokemonEvolution
  8.     {
  9.         class Evolution
  10.         {
  11.             public string EvolutionType { get; set; }
  12.             public long EvolutionIndex { get; set; }
  13.  
  14.             public Evolution(string evolutionType, long evolutionIndex)
  15.             {
  16.                 this.EvolutionType = evolutionType;
  17.                 this.EvolutionIndex = evolutionIndex;
  18.             }
  19.         }
  20.         static void Main()
  21.         {
  22.             Dictionary<string, List<Evolution>> data = new Dictionary<string, List<Evolution>>();
  23.  
  24.             string input = Console.ReadLine();
  25.  
  26.             while (input != "wubbalubbadubdub")
  27.             {
  28.                 string[] tokens = input.Split(new char[] { '-', '>', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  29.  
  30.                 string pokemonName = tokens[0];
  31.  
  32.                 /*if (tokens.Length == 1 && data.ContainsKey(pokemonName))
  33.                 {
  34.                     PrintPokemons(pokemonName, data);
  35.                 }*/
  36.                 if (tokens.Length == 1)
  37.                 {
  38.                     if(data.ContainsKey(pokemonName))
  39.                     {
  40.                         PrintPokemons(pokemonName, data);
  41.                     }                  
  42.                 }
  43.                
  44.                 else
  45.                 {
  46.                    // try
  47.                    // {
  48.                         string evolutionType = tokens[1];
  49.                         long evolutionIndex = long.Parse(tokens[2]);
  50.  
  51.                         Evolution evolution = new Evolution(evolutionType, evolutionIndex);
  52.  
  53.                         if (!data.ContainsKey(pokemonName))
  54.                         {
  55.                             data.Add(pokemonName, new List<Evolution>());
  56.                         }
  57.                         data[pokemonName].Add(evolution);
  58.                    // }
  59.                    // catch
  60.                    // {
  61.                  
  62.                    // }
  63.  
  64.                 }
  65.                 input = Console.ReadLine();
  66.             }
  67.  
  68.             foreach (var pokemonData in data)
  69.             {
  70.                 string pokemonName = pokemonData.Key;
  71.                 List<Evolution> evolutions = pokemonData.Value;
  72.  
  73.                 Console.WriteLine($"# {pokemonName}");
  74.  
  75.                 foreach (Evolution evolutionData in evolutions.OrderByDescending(e => e.EvolutionIndex))
  76.                 {
  77.                     string evolutionType = evolutionData.EvolutionType;
  78.                     long evolutionIndex = evolutionData.EvolutionIndex;
  79.  
  80.                     Console.WriteLine($"{evolutionType} <-> {evolutionIndex}");
  81.                 }
  82.             }
  83.  
  84.         }
  85.  
  86.         private static void PrintPokemons(string pokemonName, Dictionary<string, List<Evolution>> data)
  87.         {
  88.             foreach (var item in data.Where(k => k.Key == pokemonName))
  89.             {
  90.                 Console.WriteLine($"# {pokemonName}");
  91.  
  92.                 List<Evolution> evolutionData = item.Value;
  93.  
  94.                 foreach (var evolution in evolutionData)
  95.                 {
  96.                     string evolutionType = evolution.EvolutionType;
  97.                     long evolutionIndex = evolution.EvolutionIndex;
  98.  
  99.                     Console.WriteLine($"{evolutionType} <-> {evolutionIndex}");
  100.                 }
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment