Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem04
- {
- class Program
- {
- static void Main(string[] args)
- {
- var users = new Dictionary<string, List<String>>();
- string input;
- while (!(input = Console.ReadLine()).Equals("Lumpawaroo"))
- {
- if (input.Contains("|"))
- {
- var tokens = input.Split(new[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
- var currentForce = tokens[0];
- var currentUser = tokens[1];
- if (users.Any(p => p.Value.Contains(currentUser)))
- {
- continue;
- }
- if (!users.ContainsKey(currentForce))
- {
- users.Add(currentForce, new List<string>());
- }
- if (!users[currentForce].Contains(currentUser))
- {
- users[currentForce].Add(currentUser);
- }
- }
- else if (input.Contains("->"))
- {
- var tokens = input.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
- var currentUser = tokens[0];
- var currentSide = tokens[1];
- if (!users.Any(p => p.Value.Contains(currentUser)))
- {
- if (!users.ContainsKey(currentSide))
- {
- users.Add(currentSide, new List<string>());
- }
- users[currentSide].Add(currentUser);
- Console.WriteLine($"{currentUser} joins the {currentSide} side!");
- }
- else
- {
- users.First(p => p.Value.Contains(currentUser)).Value.Remove(currentUser);
- Console.WriteLine($"{currentUser} joins the {currentSide} side!");
- if (!users.ContainsKey(currentSide))
- {
- users.Add(currentSide,new List<string>());
- }
- users[currentSide].Add(currentUser);
- }
- }
- }
- foreach (var user in users.OrderByDescending(p => p.Value.Count).ThenBy(p => p.Key))
- {
- if (!user.Value.Any()) continue;
- Console.WriteLine($"Side: {user.Key}, Members: {user.Value.Count}");
- user.Value.OrderBy(p => p).ToList().ForEach(p => Console.WriteLine($"! {p}"));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement