Advertisement
Kristina_Ivanova

Untitled

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