PetarNeshkov5360

ForceBook

Apr 24th, 2021
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _09ForceBook
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var database = new Dictionary<string, List<string>>();
  12. var forceUsers = new List<string>();
  13.  
  14. string input = string.Empty;
  15. while ((input = Console.ReadLine()) != "Lumpawaroo")
  16. {
  17. if (input.IndexOf(" | ") >= 0)
  18. {
  19. string[] tokens = input.Split(" | ");
  20. string forceSide = tokens[0];
  21. string forceUser = tokens[1];
  22.  
  23. if (!forceUsers.Contains(forceUser))
  24. {
  25. if (!database.ContainsKey(forceSide))
  26. {
  27. database.Add(forceSide, new List<string>() { forceUser });
  28. }
  29. else
  30. {
  31. database[forceSide].Add(forceUser);
  32. }
  33. }
  34.  
  35. forceUsers.Add(forceUser);
  36. }
  37. else
  38. {
  39. string[] tokens = input.Split(" -> ");
  40. string forceUser = tokens[0];
  41. string forceSide = tokens[1];
  42.  
  43. // change sides
  44. if (forceUsers.Contains(forceUser))
  45. {
  46. string userCurrentSide = string.Empty;
  47. foreach (var key in database.Keys)
  48. {
  49. if (database[key].Contains(forceUser))
  50. {
  51. userCurrentSide = key;
  52. break;
  53. }
  54. }
  55.  
  56. if (!database.ContainsKey(forceSide))
  57. {
  58. database[forceSide] = new List<string>();
  59. }
  60. database[userCurrentSide].Remove(forceUser);
  61. database[forceSide].Add(forceUser);
  62. }
  63. else
  64. {
  65. if (!database.ContainsKey(forceSide))
  66. {
  67. database.Add(forceSide, new List<string>() { forceUser });
  68. }
  69. else
  70. {
  71. database[forceSide].Add(forceUser);
  72. }
  73. }
  74.  
  75. Console.WriteLine($"{forceUser} joins the {forceSide} side!");
  76. if (!forceUsers.Contains(forceUser))
  77. {
  78. forceUsers.Add(forceUser);
  79. }
  80. }
  81. }
  82.  
  83.  
  84. foreach (var item in database.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
  85. {
  86. string forceSide = item.Key;
  87. var members = item.Value;
  88. if (members.Count > 0)
  89. {
  90. Console.WriteLine($"Side: {forceSide}, Members: {members.Count}");
  91. foreach (var member in members.OrderBy(x => x))
  92. {
  93. Console.WriteLine($"! {member}");
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment