Advertisement
simeon3000

04. CODE: Phoenix Oscar Romeo November

Sep 6th, 2017
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1.             var data = new Dictionary<string, HashSet<string>>();
  2.  
  3.             string input = Console.ReadLine();
  4.  
  5.             while (input != "Blaze it!")
  6.             {
  7.                 string[] myArr = input
  8.                     .Split(new string[] { " -> " }, StringSplitOptions.None);
  9.  
  10.                 string creature = myArr[0];
  11.                 string squadMate = myArr[1];
  12.  
  13.                 if (!data.ContainsKey(creature))
  14.                 {
  15.                     data.Add(creature, new HashSet<string>());
  16.                 }
  17.  
  18.                 if (creature != squadMate)
  19.                 {
  20.                     data[creature].Add(squadMate);
  21.                 }
  22.  
  23.                 input = Console.ReadLine();
  24.             }
  25.  
  26.             var result = new Dictionary<string, List<string>>();
  27.  
  28.             foreach (var item in data)
  29.             {
  30.                 result.Add(item.Key, new List<string>());
  31.  
  32.                 foreach (var mate in item.Value)
  33.                 {
  34.                     if (data.ContainsKey(mate) && data[mate].Contains(item.Key))
  35.                     {
  36.                         continue;
  37.                     }
  38.  
  39.                     else
  40.                     {
  41.                         result[item.Key].Add(mate);
  42.                     }
  43.                 }
  44.             }
  45.  
  46.             foreach (var item in result.OrderByDescending(c => c.Value.Count))
  47.             {
  48.                 Console.WriteLine($"{item.Key} : {item.Value.Count}");
  49.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement