Advertisement
Prohause

Force Book

Mar 7th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem04
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var users = new Dictionary<string, List<String>>();
  12.  
  13. string input;
  14.  
  15. while (!(input = Console.ReadLine()).Equals("Lumpawaroo"))
  16. {
  17. if (input.Contains("|"))
  18. {
  19. var tokens = input.Split(new[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
  20.  
  21. var currentForce = tokens[0];
  22. var currentUser = tokens[1];
  23.  
  24. if (users.Any(p => p.Value.Contains(currentUser)))
  25. {
  26. continue;
  27. }
  28.  
  29. if (!users.ContainsKey(currentForce))
  30. {
  31. users.Add(currentForce, new List<string>());
  32. }
  33.  
  34. if (!users[currentForce].Contains(currentUser))
  35. {
  36. users[currentForce].Add(currentUser);
  37. }
  38. }
  39. else if (input.Contains("->"))
  40. {
  41. var tokens = input.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  42. var currentUser = tokens[0];
  43. var currentSide = tokens[1];
  44.  
  45. if (!users.Any(p => p.Value.Contains(currentUser)))
  46. {
  47. if (!users.ContainsKey(currentSide))
  48. {
  49. users.Add(currentSide, new List<string>());
  50. }
  51.  
  52. users[currentSide].Add(currentUser);
  53. Console.WriteLine($"{currentUser} joins the {currentSide} side!");
  54. }
  55. else
  56. {
  57. users.First(p => p.Value.Contains(currentUser)).Value.Remove(currentUser);
  58. Console.WriteLine($"{currentUser} joins the {currentSide} side!");
  59.  
  60. if (!users.ContainsKey(currentSide))
  61. {
  62. users.Add(currentSide,new List<string>());
  63. }
  64. users[currentSide].Add(currentUser);
  65. }
  66. }
  67. }
  68. foreach (var user in users.OrderByDescending(p => p.Value.Count).ThenBy(p => p.Key))
  69. {
  70. if (!user.Value.Any()) continue;
  71.  
  72. Console.WriteLine($"Side: {user.Key}, Members: {user.Value.Count}");
  73. user.Value.OrderBy(p => p).ToList().ForEach(p => Console.WriteLine($"! {p}"));
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement