Advertisement
ivanov_ivan

Pokemon Evo - C#

Nov 3rd, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. namespace SomeSol
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, List<string>> inputMap = new Dictionary<string, List<string>>();
  12.  
  13.             string input;
  14.  
  15.             while ("wubbalubbadubdub" != (input = Console.ReadLine()))
  16.             {
  17.                 string[] tokens = input.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.                 if (tokens.Length > 1)
  20.                 {
  21.                     if (!inputMap.ContainsKey(tokens[0]))
  22.                     {
  23.                         inputMap.Add(tokens[0], new List<string>());
  24.                     }
  25.  
  26.                     string str = tokens[1] + " <-> " + tokens[2];
  27.                     inputMap[tokens[0]].Add(str);
  28.                 }
  29.                 else if (inputMap.ContainsKey(tokens[0]))
  30.                 {
  31.                     Console.WriteLine($"# {tokens[0]}");
  32.                     inputMap[tokens[0]].ForEach(Console.WriteLine);
  33.                 }
  34.             }
  35.  
  36.             foreach (var keyValuePair in inputMap)
  37.             {
  38.                 Console.WriteLine($"# {keyValuePair.Key}");
  39.  
  40.                 var ordered = keyValuePair.Value
  41.                     .OrderByDescending(
  42.                         (a) => int.Parse(a.Split(new[] { " <-> " }, StringSplitOptions.RemoveEmptyEntries)[1])).ToList();
  43.  
  44.                 ordered.ForEach(Console.WriteLine);
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement