Advertisement
bullit3189

Force Book - Dictionaries

Jan 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _09ForceBook
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, string> nameSide = new Dictionary<string, string>();
  12.  
  13. while (true)
  14. {
  15. string command = Console.ReadLine();
  16.  
  17. if (command == "Lumpawaroo")
  18. {
  19. break;
  20. }
  21.  
  22. if (command.Contains('|'))
  23. {
  24. string[] tokens = command.Split(" | ");
  25.  
  26. string forceSide = tokens[0];
  27. string forceUser = tokens[1];
  28.  
  29. if (!nameSide.ContainsKey(forceUser))
  30. {
  31. nameSide[forceUser] = forceSide;
  32. }
  33. }
  34. else
  35. {
  36. string[] tokens = command.Split(" -> ");
  37.  
  38. string forceUser = tokens[0];
  39. string forceSide = tokens[1];
  40.  
  41. if (nameSide.ContainsKey(forceUser))
  42. {
  43. nameSide[forceUser] = forceSide;
  44. }
  45. else
  46. {
  47. nameSide[forceUser] = forceSide;
  48. }
  49.  
  50. Console.WriteLine($"{forceUser} joins the {forceSide} side!");
  51. }
  52. }
  53.  
  54. var filteredNameSide = nameSide.GroupBy(x => x.Value).OrderByDescending(x => x.Count()).ThenBy(x => x.Key);
  55.  
  56. foreach (var kvp in filteredNameSide)
  57. {
  58. string side = kvp.Key;
  59.  
  60. var nameSideValue = kvp;
  61.  
  62. Console.WriteLine($"Side: {side}, Members: {nameSideValue.Count()}");
  63.  
  64. foreach (var kvpValue in nameSideValue.OrderBy(x => x.Key))
  65. {
  66. string name = kvpValue.Key;
  67.  
  68. Console.WriteLine($"! {name}");
  69. }
  70. }
  71.  
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement