Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _12._ExamPreparation1
- {
- class ExamPreparation1
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Dictionary<string, Dictionary<string, List<int>>> pokemonNames = new Dictionary<string, Dictionary<string, List<int>>>();
- while (input != "wubbalubbadubdub")
- {
- string pattern = @"(?<pokemon>[A-Za-z]+)( -> )(?<evolution>[A-Za-z]+)( -> )(?<index>\d+)";
- MatchCollection matches = Regex.Matches(input, pattern);
- foreach (Match item in matches)
- {
- if (!pokemonNames.ContainsKey(item.Groups["pokemon"].ToString()))
- {
- Dictionary<string, List<int>> current = new Dictionary<string, List<int>>();
- current.Add(item.Groups["evolution"].ToString(), new List<int>());
- current[item.Groups["evolution"].ToString()].Add(int.Parse(item.Groups["index"].ToString()));
- pokemonNames.Add(item.Groups["pokemon"].ToString(), current);
- }
- else
- {
- if (!pokemonNames[item.Groups["pokemon"].ToString()].ContainsKey(item.Groups["evolution"].ToString()))
- {
- Dictionary<string, List<int>> current = new Dictionary<string, List<int>>();
- pokemonNames[item.Groups["pokemon"].ToString()].Add(item.Groups["evolution"].ToString(), new List<int> { int.Parse(item.Groups["index"].ToString()) });
- }
- else
- {
- pokemonNames[item.Groups["pokemon"].ToString()][item.Groups["evolution"].ToString()].Add(int.Parse(item.Groups["index"].ToString()));
- }
- }
- }
- input = Console.ReadLine();
- }
- foreach (var pokemon in pokemonNames)
- {
- Console.WriteLine($"# {pokemon.Key}");
- foreach (var evolution in pokemon.Value)
- {
- Console.Write($"{evolution.Key} <-> ");
- foreach (var item in evolution.Value)
- {
- Console.WriteLine(item);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment