TheBulgarianWolf

Force Book

Mar 5th, 2021
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ForceBook
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input;
  12.             Dictionary<string, List<string>> sides = new Dictionary<string, List<string>>();
  13.             while((input = Console.ReadLine()) != "Lumpawaroo")
  14.             {
  15.                 string[] inputArr;
  16.                 bool first = false;
  17.                 if (input.Contains("|"))
  18.                 {
  19.                     inputArr = input.Split(" | ");
  20.                     first = true;
  21.                 }
  22.                 else
  23.                 {
  24.                     inputArr = input.Split(" -> ");
  25.                 }
  26.                
  27.                 if(first == true)
  28.                 {
  29.                     string side = inputArr[0];
  30.                     string user = inputArr[1];
  31.                     if (sides.ContainsKey(side))
  32.                     {
  33.                         if (!(sides[side].Contains(user)))
  34.                         {
  35.                             sides[side].Add(user);
  36.                         }
  37.                     }
  38.                     else
  39.                     {
  40.                         sides.Add(side, new List<string>());
  41.                         sides[side].Add(user);
  42.                     }
  43.                 }
  44.                 else
  45.                 {
  46.                     string user = inputArr[0];
  47.                     string side = inputArr[1];
  48.                     bool check = false;
  49.                     foreach(var s in sides)
  50.                     {
  51.                         if (s.Value.Contains(user))
  52.                         {
  53.                             s.Value.Remove(user);
  54.                             sides[side].Add(user);
  55.                             Console.WriteLine($"{user} joins the {side} side!");
  56.                             check = true;
  57.                         }
  58.                     }
  59.  
  60.                     if (check == false)
  61.                     {
  62.                         sides[side].Add(user);
  63.                         Console.WriteLine($"{user} joins the {side} side!");
  64.                     }
  65.                 }
  66.             }
  67.  
  68.             var ordered = sides.OrderByDescending(x => x.Value.Count).ThenBy(n => n.Key).ToDictionary(x => x.Key, x => x.Value);
  69.             foreach(var side in ordered)
  70.             {
  71.                 if(side.Value.Count > 0)
  72.                 {
  73.                     Console.WriteLine("Side: " + side.Key + ", Members: " + side.Value.Count);
  74.                     side.Value.Sort();
  75.                     foreach (string name in side.Value)
  76.                     {
  77.                         Console.WriteLine("! " + name);
  78.                     }
  79.                 }
  80.                
  81.             }
  82.         }
  83.     }
  84. }
  85.  
Add Comment
Please, Sign In to add comment