Advertisement
emilangelo

Phoenix_Oscar_Romeo_November_Dynamic/91.67

Apr 7th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Problem_4_CODE_Phoenix_Oscar_Romeo_November
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             Dictionary<string, List<string>> squads = new Dictionary<string, List<string>>();
  12.  
  13.             string[] input = Console.ReadLine().Split(" -> ");
  14.             string creature = input[0];
  15.             string squadMate = input[1];
  16.             while (creature != "Blaze it!")
  17.             {
  18.                 squadMate = input[1];
  19.  
  20.                 if (creature != squadMate)
  21.                 {
  22.                     if (!squads.ContainsKey(creature))
  23.                     {
  24.                         squads[creature] = new List<string>();
  25.                         squads[creature].Add(squadMate);
  26.                     }
  27.                     else
  28.                         if (!squads[creature].Contains(squadMate))
  29.                         squads[creature].Add(squadMate);
  30.                 }
  31.  
  32.                 if (squads.ContainsKey(squadMate) && squads[creature].Contains(squadMate) && squads[squadMate].Contains(creature))
  33.                 {
  34.                     squads[creature].Remove(squadMate);
  35.                     squads[squadMate].Remove(creature);
  36.                 }
  37.  
  38.                 input = Console.ReadLine().Split(" -> ");
  39.                 creature = input[0];
  40.             }
  41.             foreach (var item in squads.OrderByDescending(x => x.Value.Count))
  42.                 Console.WriteLine(item.Key + " : " + item.Value.Count);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement