NastySwipy

Prog. Fundam. Exam-09.July.17 Part1 - 04. Pokemon Evolution

Jun 7th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _12._ExamPreparation1
  7. {
  8.     class ExamPreparation1
  9.     {
  10.       static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.             Dictionary<string, Dictionary<string, List<int>>> pokemonNames = new Dictionary<string, Dictionary<string, List<int>>>();
  14.  
  15.             while (input != "wubbalubbadubdub")
  16.             {
  17.                 string pattern = @"(?<pokemon>[A-Za-z]+)( -> )(?<evolution>[A-Za-z]+)( -> )(?<index>\d+)";
  18.                 MatchCollection matches = Regex.Matches(input, pattern);
  19.                 foreach (Match item in matches)
  20.                 {
  21.                     if (!pokemonNames.ContainsKey(item.Groups["pokemon"].ToString()))
  22.                     {
  23.                         Dictionary<string, List<int>> current = new Dictionary<string, List<int>>();
  24.                         current.Add(item.Groups["evolution"].ToString(), new List<int>());
  25.                         current[item.Groups["evolution"].ToString()].Add(int.Parse(item.Groups["index"].ToString()));
  26.                         pokemonNames.Add(item.Groups["pokemon"].ToString(), current);
  27.                     }
  28.                     else
  29.                     {
  30.                         if (!pokemonNames[item.Groups["pokemon"].ToString()].ContainsKey(item.Groups["evolution"].ToString()))
  31.                         {
  32.                             Dictionary<string, List<int>> current = new Dictionary<string, List<int>>();
  33.                             pokemonNames[item.Groups["pokemon"].ToString()].Add(item.Groups["evolution"].ToString(), new List<int> { int.Parse(item.Groups["index"].ToString()) });
  34.                         }
  35.                         else
  36.                         {
  37.                             pokemonNames[item.Groups["pokemon"].ToString()][item.Groups["evolution"].ToString()].Add(int.Parse(item.Groups["index"].ToString()));
  38.                         }
  39.                     }
  40.                 }
  41.                 input = Console.ReadLine();
  42.             }
  43.             foreach (var pokemon in pokemonNames)
  44.             {
  45.                 Console.WriteLine($"# {pokemon.Key}");
  46.                 foreach (var evolution in pokemon.Value)
  47.                 {
  48.                     Console.Write($"{evolution.Key} <-> ");
  49.                     foreach (var item in evolution.Value)
  50.                     {
  51.                         Console.WriteLine(item);
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment