anizko

09. *ForceBook

Jul 10th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _09._ForceBook
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
  11.  
  12.             string comand = Console.ReadLine();
  13.  
  14.             while (comand != "Lumpawaroo")
  15.             {
  16.                 string[] infoSplitByLine = comand.Split(" | ");
  17.                 string[] infoSplitByArrow = comand.Split(" -> ");
  18.  
  19.                 if (infoSplitByLine.Length > 1)
  20.                 {
  21.                     string forceSide = infoSplitByLine[0];
  22.                     string forceName = infoSplitByLine[1];
  23.  
  24.                     if (!dict.ContainsKey(forceSide))
  25.                     {
  26.                         dict[forceSide] = new List<string>();
  27.                     }
  28.                     if (!dict[forceSide].Contains(forceName))
  29.                     {
  30.                         dict[forceSide].Add(forceName);
  31.                     }
  32.                 }
  33.  
  34.                 else if (infoSplitByArrow.Length > 1)
  35.                 {
  36.                     string forceSide = infoSplitByArrow[1];
  37.                     string forceName = infoSplitByArrow[0];
  38.  
  39.                     string userCurrentSide = string.Empty;
  40.  
  41.                     foreach (var key in dict.Keys)
  42.                     {
  43.                         if (dict[key].Contains(forceName) && key!=forceSide)
  44.                         {
  45.                             userCurrentSide = key;
  46.                             dict[userCurrentSide].Remove(forceName);
  47.                             break;
  48.                         }
  49.                     }
  50.  
  51.                     if (!dict.ContainsKey(forceSide))
  52.                     {
  53.                         dict[forceSide] = new List<string>();
  54.                     }
  55.                     dict[forceSide].Add(forceName);
  56.                     Console.WriteLine($"{forceName} joins the {forceSide} side!");
  57.  
  58.                 }
  59.                 comand = Console.ReadLine();
  60.             }
  61.  
  62.             var result = dict.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key);
  63.  
  64.             foreach (var item in result)
  65.             {
  66.                 if (item.Value.Count > 0)
  67.                 {
  68.                     Console.WriteLine($"Side: {item.Key}, Members: {item.Value.Count}");
  69.  
  70.                     foreach (var name in item.Value.OrderBy(x=>x))
  71.                     {
  72.                         Console.WriteLine($"! {name}");
  73.                     }
  74.                 }
  75.             }
  76.  
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment