MiroslavKisov

CODEPhoenixOscarRomeoNovember

Dec 4th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.CODEPhoenixOscarRomeoNovember
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             Dictionary<string, List<string>> squads = new Dictionary<string, List<string>>();
  12.             List<string> check = new List<string>();
  13.             while (true)
  14.             {
  15.                 string input = Console.ReadLine();
  16.                 if (input == "Blaze it!")
  17.                 {
  18.                     break;
  19.                 }
  20.                 string creature = input.Substring(0, input.IndexOf('-') - 1).Trim();
  21.                 string squadMate = input.Substring(input.IndexOf('>') + 2).Trim();
  22.                 if (!squads.ContainsKey(creature))
  23.                 {
  24.                     squads.Add(creature, new List<string>());
  25.                     squads[creature].Add(squadMate);
  26.                 }
  27.                 else
  28.                 {
  29.                     if (squads[creature].Contains(squadMate) || creature == squadMate)
  30.                     {
  31.                         continue;
  32.                     }
  33.                     else
  34.                     {
  35.                         squads[creature].Add(squadMate);
  36.                     }
  37.                 }
  38.                 check.Add(squadMate + "" + creature);
  39.                 if (check.Contains(creature + "" + squadMate))
  40.                 {
  41.                     squads[creature].Remove(squadMate);
  42.                     squads[squadMate].Remove(creature);
  43.                 }
  44.             }
  45.             foreach (var squad in squads.OrderByDescending(x =>x.Value.Count))
  46.             {
  47.                 Console.WriteLine($"{squad.Key} : {squad.Value.Count()}");
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment