Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _09._ForceBook
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
- string comand = Console.ReadLine();
- while (comand != "Lumpawaroo")
- {
- string[] infoSplitByLine = comand.Split(" | ");
- string[] infoSplitByArrow = comand.Split(" -> ");
- if (infoSplitByLine.Length > 1)
- {
- string forceSide = infoSplitByLine[0];
- string forceName = infoSplitByLine[1];
- if (!dict.ContainsKey(forceSide))
- {
- dict[forceSide] = new List<string>();
- }
- if (!dict[forceSide].Contains(forceName))
- {
- dict[forceSide].Add(forceName);
- }
- }
- else if (infoSplitByArrow.Length > 1)
- {
- string forceSide = infoSplitByArrow[1];
- string forceName = infoSplitByArrow[0];
- string userCurrentSide = string.Empty;
- foreach (var key in dict.Keys)
- {
- if (dict[key].Contains(forceName) && key!=forceSide)
- {
- userCurrentSide = key;
- dict[userCurrentSide].Remove(forceName);
- break;
- }
- }
- if (!dict.ContainsKey(forceSide))
- {
- dict[forceSide] = new List<string>();
- }
- dict[forceSide].Add(forceName);
- Console.WriteLine($"{forceName} joins the {forceSide} side!");
- }
- comand = Console.ReadLine();
- }
- var result = dict.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key);
- foreach (var item in result)
- {
- if (item.Value.Count > 0)
- {
- Console.WriteLine($"Side: {item.Key}, Members: {item.Value.Count}");
- foreach (var name in item.Value.OrderBy(x=>x))
- {
- Console.WriteLine($"! {name}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment