Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace HouseParty
- {
- class Program
- {
- static void Main(string[] args)
- {
- var sidesUsersDictionary = new Dictionary<string, List<string>>();
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "Lumpawaroo")
- {
- if (input.Contains('|'))
- {
- string[] inputArray = input.Split(" | ");
- string side = inputArray[0];
- string user = inputArray[1];
- bool userAlreadyExist = false;
- foreach (var kvp in sidesUsersDictionary)
- {
- var currentList = kvp.Value;
- if (currentList.Contains(user))
- {
- userAlreadyExist = true;
- break;
- }
- }
- if (userAlreadyExist == false && sidesUsersDictionary.ContainsKey(side) == false)
- {
- sidesUsersDictionary[side] = new List<string>();
- sidesUsersDictionary[side].Add(user);
- }
- else if (userAlreadyExist == false && sidesUsersDictionary.ContainsKey(side) == true)
- {
- sidesUsersDictionary[side].Add(user);
- }
- }
- else if (input.Contains("->"))
- {
- string[] inputArray = input.Split(" -> ");
- string user = inputArray[0];
- string side = inputArray[1];
- bool userAlreadyExist = false;
- string sideWhereIsUser = string.Empty;
- foreach (var kvp in sidesUsersDictionary)
- {
- var currentList = kvp.Value;
- if (currentList.Contains(user))
- {
- userAlreadyExist = true;
- sideWhereIsUser = kvp.Key;
- break;
- }
- }
- if (userAlreadyExist == false && sidesUsersDictionary.ContainsKey(side) == false)
- {
- sidesUsersDictionary[side] = new List<string>();
- sidesUsersDictionary[side].Add(user);
- PrintWhereUserJoined(user, side);
- }
- else if (userAlreadyExist == false && sidesUsersDictionary.ContainsKey(side) == true)
- {
- sidesUsersDictionary[side].Add(user);
- PrintWhereUserJoined(user, side);
- }
- else if (userAlreadyExist == true && sidesUsersDictionary.ContainsKey(side) == false)
- {
- sidesUsersDictionary[sideWhereIsUser].Remove(user);
- sidesUsersDictionary[side] = new List<string>();
- sidesUsersDictionary[side].Add(user);
- PrintWhereUserJoined(user, side);
- }
- else if (userAlreadyExist==true&& sidesUsersDictionary.ContainsKey(side)==true && sideWhereIsUser!=side)
- {
- sidesUsersDictionary[sideWhereIsUser].Remove(user);
- sidesUsersDictionary[side].Add(user);
- PrintWhereUserJoined(user, side);
- }
- }
- }
- PrintAllUsersInAllForceSides(sidesUsersDictionary);
- }
- private static void PrintAllUsersInAllForceSides(Dictionary<string, List<string>> sidesUsersDictionary)
- {
- foreach (var kvp in sidesUsersDictionary.Where(x => x.Value.Count > 0).OrderByDescending(x => x.Value.Count)
- .ThenBy(x => x.Key))
- {
- string side = kvp.Key;
- var listOfUser = kvp.Value;
- Console.WriteLine($"Side: {side}, Members: {listOfUser.Count()}");
- foreach (var users in listOfUser.OrderBy(x => x))
- {
- Console.WriteLine($"! {users}");
- }
- }
- }
- private static void PrintWhereUserJoined(string user, string side)
- {
- Console.WriteLine($"{user} joins the {side} side!");
- }
- }
- }
Add Comment
Please, Sign In to add comment