Advertisement
Lyubohd

Untitled

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