Guest User

Untitled

a guest
Feb 12th, 2017
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace TeamworkProjects
  6. {
  7. class TeamworkProjects
  8. {
  9. static void Main()
  10. {
  11. Dictionary<string, Team> teams = new Dictionary<string, Team>();
  12. Team currentTeam = new Team("","",new List<string>());
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. for (int i = 0; i < n; i++)
  16. {
  17. string[] inputLine = Console.ReadLine().Split('-');
  18. string currentCreatorName = inputLine[0];
  19. string currentTeamName = inputLine[1];
  20.  
  21. //I have to make new list for members or I have null value exeption.List must have count 0.
  22. List<string> membersList = new List<string>();
  23.  
  24. currentTeam = new Team(currentTeamName, currentCreatorName, membersList);
  25.  
  26. //Team doesn't contains creator name.
  27. if (!teams.Values.Any(x => x.TeamName.Equals(currentTeamName)))
  28. {
  29. currentTeam.TeamName = currentTeamName;
  30.  
  31. //If Team -> team name - doesn't contains current team name.
  32. if (!teams.Values.Any(x => x.TeamName.Equals(currentTeamName)))
  33. {
  34. teams.Add(currentCreatorName, currentTeam);
  35. Console.WriteLine($"Team {currentTeamName} has been created by {currentCreatorName}!");
  36. }
  37. else
  38. {
  39. //Team Team -> team name - contains current team name.
  40. Console.WriteLine($"{currentCreatorName} cannot create another team!");
  41. }
  42. }
  43. else
  44. {
  45. //Team contains creator name.
  46. Console.WriteLine("Team {0} was already created!", currentTeamName);
  47. }
  48.  
  49. }
  50.  
  51. string secondInput = Console.ReadLine();
  52. while (!secondInput.Equals("end of assignment"))
  53. {
  54. string[] inputArgs = secondInput.Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  55. string currentUser = inputArgs[0];
  56. string teamToJoin = inputArgs[1];
  57.  
  58. //If list of teams does contains team name and current user want to join -> teamToJoin.
  59. if (teams.Values.Any(x => x.TeamName.Equals(teamToJoin)))
  60. {
  61. //If teamToJoin doesn't contains members equal to current user
  62. //AND if teamToJoin doesn't contains creator name equal to current user.
  63. if (!teams.Values.Any(c => c.Members.Any(x => x.Equals(currentUser))) && !teams.Values.Any(c => c.CreatorName.Equals(currentUser)))
  64. {
  65. var creatorOfTheTeam = teams.First(x => x.Value.TeamName.Equals(teamToJoin));
  66. teams[creatorOfTheTeam.Key].Members.Add(currentUser);
  67. }
  68. else
  69. {
  70. //If teamToJoin does contains member equal to current user
  71. //OR teamToJoin does contains creator name equal to currentUser.
  72. Console.WriteLine("Member {0} cannot join team {1}!", currentUser, teamToJoin);
  73. }
  74. }
  75. else
  76. {
  77. //If list of teams doesn't contains team name.
  78. Console.WriteLine("Team {0} does not exist!", teamToJoin);
  79. }
  80.  
  81. secondInput = Console.ReadLine();
  82. }
  83.  
  84. foreach (var team in teams.Values.Where(c => c.Members.Count > 0).OrderByDescending(x => x.Members.Count).ThenBy(c => c.TeamName))
  85. {
  86. Console.WriteLine("{0}", team.TeamName);
  87. Console.WriteLine("- {0}", team.CreatorName);
  88.  
  89. foreach (var member in team.Members.OrderBy(x=>x))
  90. {
  91. Console.WriteLine("-- {0}", member);
  92. }
  93. }
  94.  
  95. Console.WriteLine("Teams to disband:");
  96. foreach (var teamToDisband in teams.Where(c => c.Value.Members.Count == 0).OrderBy(x => x.Value.TeamName))
  97. {
  98. Console.WriteLine($"{teamToDisband.Value.TeamName}");
  99. }
  100.  
  101. }
  102. }
  103.  
  104. class Team
  105. {
  106. private string teamName;
  107.  
  108. private string creatorName;
  109.  
  110. private List<string> members;
  111.  
  112.  
  113. public Team(string teamName, string creatorName, List<string> members)
  114. {
  115. this.teamName = teamName;
  116. this.creatorName = creatorName;
  117. this.members = members;
  118. }
  119.  
  120. public Team(string teamName, string creatorName) : this(teamName, creatorName, null)
  121. {
  122.  
  123. }
  124.  
  125. public Team(string teamName) : this(teamName, null, null)
  126. {
  127.  
  128. }
  129.  
  130. public string TeamName
  131. {
  132. get
  133. {
  134. return teamName;
  135. }
  136. set
  137. {
  138. value = teamName;
  139. }
  140.  
  141. }
  142.  
  143. public string CreatorName
  144. {
  145. get
  146. {
  147. return creatorName;
  148. }
  149. set
  150. {
  151. value = creatorName;
  152. }
  153. }
  154.  
  155. public List<string> Members
  156. {
  157. get
  158. {
  159. return members;
  160. }
  161. set
  162. {
  163. value = members;
  164. }
  165. }
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment