Advertisement
Guest User

ForceBook

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