Advertisement
Guest User

Untitled

a guest
Jul 17th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _09._ForceBook
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string input = string.Empty;
  12. string side = string.Empty;
  13. string name = string.Empty;
  14.  
  15. var sides = new Dictionary<string, List<string>>();
  16.  
  17. while ((input = Console.ReadLine()) != "Lumpawaroo")
  18. {
  19.  
  20. if (input.Contains("|"))
  21. {
  22. side = input.Split(" | ")[0];
  23. name = input.Split(" | ")[1];
  24.  
  25.  
  26. if (!sides.ContainsKey(side))
  27. {
  28. sides.Add(side, new List<string>());
  29. sides[side].Add(name);
  30. }
  31. else
  32. {
  33. if (!sides[side].Contains(name))
  34. {
  35. sides[side].Add(name);
  36. }
  37. }
  38. }
  39. else if (input.Contains("->"))
  40. {
  41. side = input.Split(" -> ")[1];
  42. name = input.Split(" -> ")[0];
  43.  
  44. int index = 0;
  45.  
  46. foreach (var item in sides)
  47. {
  48. if (item.Value.Contains(name))
  49. {
  50. index = item.Value.IndexOf(name);
  51. item.Value.RemoveAt(index);
  52. break;
  53. }
  54. }
  55.  
  56. if (sides.ContainsKey(side))
  57. {
  58. Console.WriteLine($"{name} joins the {side} side!");
  59. sides[side].Add(name);
  60. }
  61. else
  62. {
  63. Console.WriteLine($"{name} joins the {side} side!");
  64. sides.Add(side, new List<string>());
  65. sides[side].Add(name);
  66. }
  67.  
  68. }
  69. }
  70.  
  71. sides = sides.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key).ToDictionary(a => a.Key, b => b.Value);
  72.  
  73. foreach (var item in sides)
  74. {
  75. if (item.Value.Count == 0)
  76. {
  77. continue;
  78. }
  79. Console.WriteLine($"Side: {item.Key}, Members: {item.Value.Count}");
  80. sides[item.Key].Sort();
  81. foreach (var items in sides[item.Key])
  82. {
  83. Console.WriteLine($"! {items}");
  84. }
  85. }
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement