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