Guest User

Untitled

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