Advertisement
Lazov

04._ForceBook

Apr 24th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04._ForceBook
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string line = Console.ReadLine();
  12. Dictionary<string, List<string>> listOfSides = new Dictionary<string, List<string>>();
  13.  
  14.  
  15. while (line != "Lumpawaroo")
  16. {
  17. List<string> users = new List<string>();
  18. if (line.Contains("|"))
  19. {
  20. string[] input = line.Split(new [] { " | " }, StringSplitOptions.RemoveEmptyEntries);
  21. string side = input[0];
  22. string user = input[1];
  23. if (!listOfSides.ContainsKey(side))
  24. {
  25. if (!users.Contains(user))
  26. {
  27. users.Add(user);
  28. listOfSides.Add(side, users);
  29. }
  30. }
  31. //Is it necessary to make some other cheques
  32. }
  33. else
  34. {
  35. string[] input = line.Split(new [] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  36. string side = input[1];
  37. string user = input[0];
  38.  
  39. if (side == "Lighter" && listOfSides["Darker"].Contains(user))
  40. {
  41. listOfSides["Darker"].Remove(user);
  42. }
  43. else if (side == "Darker" && listOfSides["Lighter"].Contains(user))
  44. {
  45. listOfSides["Lighter"].Remove(user);
  46. }
  47.  
  48. if (!listOfSides.ContainsKey(side))
  49. {
  50. if (!users.Contains(user))
  51. {
  52. users.Add(user);
  53. listOfSides.Add(side, users);
  54. Console.WriteLine($"{user} joins the {side} side!");
  55. }
  56. //Is it necessary to make some other cheques
  57. }
  58. else
  59. {
  60. listOfSides[side].Add(user);
  61. Console.WriteLine($"{user} joins the {side} side!");
  62. }
  63.  
  64. }
  65.  
  66. line = Console.ReadLine();
  67. }
  68.  
  69. foreach (var pear in listOfSides.OrderBy(x=>x.Key))
  70. {
  71. if (pear.Value.Count > 0)
  72. {
  73. Console.WriteLine($"Side: {pear.Key}, Members: {pear.Value.Count}");
  74. }
  75.  
  76. foreach (var item in pear.Value.OrderBy(x=>x))
  77. {
  78. Console.WriteLine($"! {string.Join(',', item)}");
  79. }
  80. }
  81.  
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement