Advertisement
YavorGrancharov

CODE:PhoenixOscarRomeoNovember

Jan 4th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CODEPhoenixOscarRomeoNovember
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.  
  13.             Dictionary<string, HashSet<string>> data = new Dictionary<string, HashSet<string>>();
  14.  
  15.             while (input != "Blaze it!")
  16.             {
  17.                 string[] tokens = input.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  18.                 string creature = tokens[0];
  19.                 string squadMate = tokens[1];
  20.  
  21.                 if (!data.ContainsKey(creature))
  22.                 {
  23.                     data.Add(creature, new HashSet<string>());
  24.                 }
  25.                 if (creature != squadMate)
  26.                 {
  27.                     data[creature].Add(squadMate);
  28.                 }
  29.  
  30.                 input = Console.ReadLine();
  31.             }
  32.  
  33.             Dictionary<string, List<string>> output = new Dictionary<string, List<string>>();
  34.  
  35.             foreach (var record in data)
  36.             {
  37.                 output.Add(record.Key, new List<string>());
  38.  
  39.                 foreach (var mate in record.Value)
  40.                 {
  41.                     if (data.ContainsKey(mate) && data[mate].Contains(record.Key))
  42.                     {
  43.                         continue;
  44.                     }
  45.                     else
  46.                     {
  47.                         output[record.Key].Add(mate);
  48.                     }
  49.                 }
  50.             }
  51.  
  52.             foreach (var entry in output.OrderByDescending(x => x.Value.Count))
  53.             {
  54.                 Console.WriteLine("{0} : {1}", entry.Key, string.Join(" ", entry.Value.Count));
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement