Advertisement
miroLLL

ForceBook

Apr 4th, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04Problem_MyExam
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = string.Empty;
  12.  
  13.             SortedDictionary<string, List<string>> forceSides = new SortedDictionary<string, List<string>>();
  14.  
  15.             while ((input = Console.ReadLine()) != "Lumpawaroo")
  16.             {
  17.                 string[] splitInput = input.Split(new string[] { " -> ", " | " }, StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.                 string side = string.Empty;
  20.                 string user = string.Empty;
  21.                 string oldSide = string.Empty;
  22.  
  23.                 if (input.Contains(" -> "))
  24.                 {
  25.                     user = splitInput[0];
  26.                     side = splitInput[1];
  27.  
  28.                     if (forceSides.ContainsKey(side) == false)
  29.                     {
  30.                         forceSides.Add(side, new List<string>());
  31.                         forceSides[side].Add(user);
  32.                     }
  33.                     else
  34.                     {
  35.                         if (forceSides[side].Contains(user))
  36.                         {
  37.                             forceSides[side].Remove(user);
  38.                         }
  39.  
  40.                         forceSides[side].Add(user);
  41.                     }
  42.  
  43.                     Console.WriteLine($"{user} joins the {side} side!");
  44.                 }
  45.                 else if (input.Contains(" | "))
  46.                 {
  47.                     user = splitInput[1];
  48.                     side = splitInput[0];
  49.  
  50.                     if (forceSides.ContainsKey(side) == false)
  51.                     {
  52.                         forceSides.Add(side, new List<string>());
  53.                     }
  54.  
  55.                     if (forceSides[side].Contains(user) == false)
  56.                     {
  57.                         forceSides[side].Add(user);
  58.                     }
  59.                 }
  60.             }
  61.  
  62.             foreach (var sideAndUsers in forceSides.OrderByDescending(x => x.Value.Count()))
  63.             {
  64.                 Console.WriteLine($"Side: {sideAndUsers.Key}, Members: {sideAndUsers.Value.Count}");
  65.  
  66.                 foreach (var user in sideAndUsers.Value.OrderBy(x => x))
  67.                 {
  68.                     Console.WriteLine($"! {user}");
  69.                 }
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement