Advertisement
Ivakis

Teamwork Projects

Oct 21st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace P09_TeamProjects
  8. {
  9. class Team
  10. {
  11. public string TeamName { get; set; }
  12. public List<string> MembersList { get; set; }
  13. public string CreatorName { get; set; }
  14. }
  15.  
  16. class StartUp
  17. {
  18. static void Main(string[] args)
  19. {
  20. int n = int.Parse(Console.ReadLine());
  21.  
  22. List<Team> teams = new List<Team>();
  23.  
  24. createTeams(n, teams);
  25. getUsersToMembersList(teams);
  26. printResult(teams);
  27. }
  28.  
  29. private static void printResult(List<Team> teams)
  30. {
  31. foreach (var item in teams.Where(t => t.MembersList.Count > 0).OrderByDescending(t => t.MembersList.Count).ThenBy(t => t.TeamName))
  32. {
  33. Console.WriteLine(item.TeamName);
  34. Console.WriteLine($"- {item.CreatorName}");
  35.  
  36. foreach (var member in item.MembersList.OrderBy(a => a))
  37. {
  38. Console.WriteLine($"-- {member}");
  39. }
  40. }
  41. Console.WriteLine("Teams to disband:");
  42.  
  43. foreach (var item in teams.Where(t => t.MembersList.Count < 1).OrderBy(t => t.TeamName))
  44. {
  45.  
  46. Console.WriteLine(item.TeamName);
  47. }
  48. }
  49.  
  50. private static void getUsersToMembersList(List<Team> teams)
  51. {
  52. string command = Console.ReadLine();
  53.  
  54. while (command != "end of assignment")
  55. {
  56. var commandArgs = command.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
  57. var userName = commandArgs[0];
  58. var teamName = commandArgs[1];
  59.  
  60. bool teamExists = false;
  61. bool userIsAlreadyInATeam = false;
  62. bool userIsCreatorOfATeam = false;
  63.  
  64. foreach (var t in teams)
  65. {
  66. if (t.TeamName == teamName)
  67. {
  68. teamExists = true;
  69. }
  70. if (t.MembersList.Contains(userName))
  71. {
  72. userIsAlreadyInATeam = true;
  73. }
  74. if(t.CreatorName == userName)
  75. {
  76. userIsCreatorOfATeam = true;
  77. }
  78. }
  79.  
  80.  
  81. if (!teamExists)
  82. {
  83. Console.WriteLine($"Team {teamName} does not exist!");
  84. }
  85. else if (userIsAlreadyInATeam || userIsCreatorOfATeam)
  86. {
  87. Console.WriteLine($"Member {userName} cannot join team {teamName}!");
  88. }
  89. else
  90. {
  91. foreach (var t in teams)
  92. {
  93. if (t.TeamName == teamName)
  94. {
  95. t.MembersList.Add(userName);
  96. }
  97. }
  98. }
  99.  
  100. command = Console.ReadLine();
  101. }
  102. }
  103.  
  104. private static void createTeams(int n, List<Team> teams)
  105. {
  106. for (int i = 0; i < n; i++)
  107. {
  108. var input = Console.ReadLine().Split('-');
  109. var creator = input[0];
  110. var nameOfTeam = input[1];
  111.  
  112. Team team = new Team();
  113. team.TeamName = nameOfTeam;
  114. team.CreatorName = creator;
  115. team.MembersList = new List<string>();
  116.  
  117. bool teamAlreadyCreated = false;
  118. bool userAlreadyHasAteam = false;
  119.  
  120. foreach (var t in teams)
  121. {
  122. if (t.TeamName == team.TeamName)
  123. {
  124. teamAlreadyCreated = true;
  125. }
  126. if (t.CreatorName == team.CreatorName)
  127. {
  128. userAlreadyHasAteam = true;
  129. }
  130. }
  131.  
  132. if (teamAlreadyCreated)
  133. {
  134. Console.WriteLine($"Team {team.TeamName} was already created!");
  135. continue;
  136. }
  137. else if (userAlreadyHasAteam)
  138. {
  139. Console.WriteLine($"{team.CreatorName} cannot create another team!");
  140. continue;
  141. }
  142. else
  143. {
  144. teams.Add(team);
  145. Console.WriteLine($"Team {team.TeamName} has been created by {team.CreatorName}!");
  146. }
  147. }
  148. }
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement