Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 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. SortedDictionary<string, string> data = new SortedDictionary<string, string>();
  12.  
  13. string userName = "";
  14. string side = "";
  15.  
  16.  
  17. while (true)
  18. {
  19. string input = Console.ReadLine();
  20.  
  21. if (input == "Lumpawaroo")
  22. {
  23. break;
  24. }
  25.  
  26. if (input.Contains("|"))
  27. {
  28. string[] user = input.Split("|").Select(tag => tag.Trim()).
  29. Where(tag => !string.IsNullOrEmpty(tag)).ToArray();
  30. side = user[0];
  31. userName = user[1];
  32. if (!data.ContainsKey(userName))
  33. {
  34. data.Add(userName, null);
  35. }
  36. data[userName] = side;
  37. }
  38.  
  39. else if (input.Contains("->"))
  40. {
  41. string[] user = input.Split("->").Select(tag => tag.Trim()).
  42. Where(tag => !string.IsNullOrEmpty(tag)).ToArray();
  43. userName = user[0];
  44. side = user[1];
  45.  
  46. if (!data.ContainsKey(userName))
  47. {
  48. data.Add(userName, null);
  49. }
  50. data[userName] = side;
  51. Console.WriteLine($"{userName} joins the {side} side!");
  52. }
  53. }
  54.  
  55. Dictionary<string, int> count = new Dictionary<string, int>();
  56.  
  57. foreach (var item in data)
  58. {
  59. if (!count.ContainsKey(item.Value))
  60. {
  61. count.Add(item.Value, 0);
  62. }
  63. count[item.Value] += 1;
  64. }
  65.  
  66. foreach (var item in count.OrderBy(e=>e.Key))
  67. {
  68. Console.WriteLine($"Side: {item.Key}, Members: {item.Value}");
  69. foreach (var item2 in data)
  70. {
  71. if (item2.Value == item.Key)
  72. {
  73. Console.WriteLine($"! {item2.Key}");
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement