Advertisement
Guest User

Untitled

a guest
May 26th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. namespace _107._The_V_Logger
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. class VLogger
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. try
  13. {
  14. var dictVlogers = new Dictionary<string, Vloger>();
  15. var input = string.Empty;
  16. //Read Input
  17. while ((input = Console.ReadLine()) != "Statistics")
  18. {
  19. var splitInput = input.Split();
  20. var nameVloger = string.Empty;
  21. switch (splitInput[1])
  22. {
  23. case "joined":
  24. nameVloger = splitInput[0];
  25. if (!dictVlogers.ContainsKey(nameVloger))
  26. {
  27. var newVloger = new Vloger(nameVloger);
  28. dictVlogers.Add(nameVloger, newVloger);
  29. }
  30. break;
  31. case "followed":
  32. var nameReglarPersonFirst = splitInput[0];
  33. var nameVlogerSecond = splitInput[2];
  34.  
  35. if (nameReglarPersonFirst == nameVlogerSecond)
  36. {
  37. break;
  38. }
  39. if (dictVlogers.ContainsKey(nameVlogerSecond) && dictVlogers.ContainsKey(nameReglarPersonFirst))
  40. {
  41. var vloger = dictVlogers[nameVlogerSecond];
  42. //dobawamq imenata
  43. if (!vloger.ContainsFollowers(nameReglarPersonFirst))
  44. {
  45. vloger.AddFollowersName(nameReglarPersonFirst);
  46. }
  47. //dobawqme na vlogera followers
  48.  
  49. var fowoling = dictVlogers[nameReglarPersonFirst];
  50. if (!fowoling.ContainsFollowing(nameVlogerSecond))
  51. {
  52. fowoling.AddFollowingName(nameVlogerSecond);
  53. }
  54. }
  55. break;
  56. default:
  57. Console.WriteLine("Outher type of input");
  58. break;
  59.  
  60. }
  61. }
  62. PrintStatistic(dictVlogers);
  63. }
  64. catch (Exception ex)
  65. {
  66. Console.WriteLine(ex.Message);
  67. }
  68.  
  69. }
  70.  
  71. private static void PrintStatistic(Dictionary<string, Vloger> dictVlogers)
  72. {
  73. Console.ForegroundColor = ConsoleColor.Red;
  74. var counter = 1;
  75. Console.WriteLine($"The V-Logger has a total of {dictVlogers.Count} vloggers in its logs.");
  76. foreach (var vloger in dictVlogers.
  77. OrderByDescending(x => x.Value.FollowersCount()).
  78. ThenBy(x => x.Value.FollowingCount()))
  79. {
  80. if (counter == 1)
  81. {
  82. Console.WriteLine($"{counter}. {vloger.Key} : {vloger.Value.FollowersCount()} followers, {vloger.Value.FollowingCount()} following");
  83. var listFollowers = vloger.Value.ListFollowers();
  84. foreach (var liker in listFollowers.OrderBy(x => x))
  85. {
  86. Console.WriteLine($"* {liker}");
  87. }
  88. }
  89. else
  90. {
  91. Console.WriteLine($"{counter}. {vloger.Key} : {vloger.Value.FollowersCount()} followers, {vloger.Value.FollowingCount()} following");
  92. }
  93. counter++;
  94. }
  95. Console.ForegroundColor = ConsoleColor.White;
  96. }
  97. }
  98.  
  99. class Vloger
  100. {
  101. public string vlogerName;
  102. public List<string> followers;
  103. public List<string> following;
  104. public Vloger(string name)
  105. {
  106. this.Name = name;
  107. this.Followers = new List<string>();
  108. this.Following = new List<string>();
  109. }
  110.  
  111. //following
  112. public bool ContainsFollowing(string followingName)
  113. {
  114. if (!this.Following.Contains(followingName))
  115. {
  116. return false;
  117. }
  118. return true;
  119. }
  120.  
  121. public void AddFollowingName(string followingName)
  122. {
  123. this.Following.Add(followingName);
  124. }
  125.  
  126. public List<string> ListFollowing()
  127. {
  128. return this.Following;
  129. }
  130. public int FollowingCount()
  131. {
  132. var result = this.Following.Count;
  133. return result;
  134. }
  135.  
  136. //following
  137. public bool ContainsFollowers(string followingName)
  138. {
  139. if (this.Followers.Contains(followingName))
  140. {
  141. return true;
  142. }
  143. return false;
  144. }
  145.  
  146. public void AddFollowersName(string followingName)
  147. {
  148. this.Followers.Add(followingName);
  149. }
  150.  
  151. public List<string> ListFollowers()
  152. {
  153. return this.Followers;
  154. }
  155. public int FollowersCount()
  156. {
  157. return this.Followers.Count;
  158. }
  159.  
  160. public string Name { get; set; }
  161. public List<string> Followers { get; set; }
  162. public List<string> Following { get; set; }
  163. }
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement