Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace E09_ForceBook
- {
- class Program
- {
- static void Main()
- {
- var input = Console.ReadLine();
- var forceSides = new Dictionary<string, List<string>>();
- while (input != "Lumpawaroo")
- {
- var user = string.Empty;
- var side = string.Empty;
- if (input.Contains("|"))
- {
- var tokens = input
- .Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- side = tokens[0];
- user = tokens[1];
- if (!forceSides.ContainsKey(side))
- {
- forceSides[side] = new List<string>();
- }
- if (!forceSides[side].Contains(user)
- && !forceSides.Values.Any(u=>u.Contains(user)))
- {
- forceSides[side].Add(user);
- }
- }
- else if(input.Contains("->"))
- {
- var tokens = input
- .Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- side = tokens[1];
- user = tokens[0];
- if (forceSides.Any(x => x.Value.Contains(user)))
- {
- foreach (var s in forceSides)
- {
- if (s.Value.Contains(user))
- {
- s.Value.Remove(user);
- }
- }
- if (!forceSides.ContainsKey(side))
- {
- forceSides[side] = new List<string>();
- }
- }
- else
- {
- if (!forceSides.ContainsKey(side))
- {
- forceSides[side] = new List<string>();
- }
- }
- forceSides[side].Add(user);
- Console.WriteLine($"{user} joins the {side} side!");
- }
- input = Console.ReadLine();
- }
- forceSides = forceSides.Where(s=>s.Value.Count>0)
- .OrderByDescending(s => s.Value.Count)
- .ThenBy(s => s.Key)
- .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
- foreach (var kvp in forceSides)
- {
- Console.WriteLine($"Side: {kvp.Key}, Members: {kvp.Value.Count}");
- Console.WriteLine($"! {string.Join("\r\n! ", kvp.Value.OrderBy(u=>u))}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement