Advertisement
Guest User

5. Teamwork Projects

a guest
Jun 26th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. using static _05._Teamwork_Projects.Program;
  2.  
  3. namespace _05._Teamwork_Projects
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int numberOfTeams = int.Parse(Console.ReadLine());
  10.  
  11. List<Team> teams = new List<Team>();
  12. for (int i = 0; i < numberOfTeams; i++)
  13. {
  14. List<string> teamInformation = Console.ReadLine()
  15. .Split("-")
  16. .ToList();
  17. string teamName = teamInformation[1];
  18. string creatorName = teamInformation[0];
  19.  
  20. if (IsCreated(creatorName, teamName, teams))
  21. {
  22. Team team = new Team(creatorName, teamName);
  23. teams.Add(team);
  24. Console.WriteLine($"Team {teamName} has been created by {creatorName}!");
  25. }
  26. }
  27. string input = "";
  28. while ((input = Console.ReadLine()) != "end of assignment")
  29. {
  30. List<string> assignment = input
  31. .Split("->")
  32. .ToList();
  33. string memberName = assignment[0];
  34. string teamName = assignment[1];
  35. bool teamExist = false;
  36. foreach (Team team in teams)
  37. {
  38. if (team.TeamName == teamName)
  39. {
  40. teamExist = true;
  41. if (teams.Any(x => x.Members.Contains(memberName) || teams.Any(x => x.Creator == memberName)))
  42. {
  43. Console.WriteLine($"Member {memberName} cannot join team {teamName}!");
  44. break;
  45. }
  46. else
  47. {
  48. team.Members.Insert(team.Members.Count, memberName);
  49. break;
  50. }
  51. }
  52. }
  53. if (!teamExist)
  54. {
  55. Console.WriteLine($"Team {teamName} does not exist!");
  56. }
  57. }
  58. foreach (Team team in teams.OrderByDescending(x => x.Members.Count).ThenBy(x => x.TeamName))
  59. {
  60. team.Members.Sort();
  61. if (team.Members.Count > 0)
  62. {
  63. Console.WriteLine($"{team.TeamName}");
  64. Console.WriteLine($"- {team.Creator}");
  65. for (int i = 0; i < team.Members.Count; i++)
  66. {
  67. Console.WriteLine($"-- {team.Members[i]}");
  68. }
  69.  
  70. }
  71. }
  72. Console.WriteLine("Teams to disband:");
  73. foreach (Team team in teams.OrderByDescending(x => x.Members.Count).ThenBy(x => x.TeamName))
  74. {
  75. if (team.Members.Count == 0)
  76. {
  77. Console.WriteLine(team.TeamName);
  78. }
  79. }
  80. }
  81. static bool IsCreated(string creator, string teamName, List<Team> teams)
  82. {
  83. bool created = true;
  84. foreach (Team team in teams)
  85. {
  86. if (teams.Any(x => x.TeamName == teamName))
  87. {
  88. created = false;
  89. Console.WriteLine($"Team {teamName} was already created!");
  90. return created;
  91.  
  92. }
  93. else if (teams.Any(x => x.Creator == creator))
  94. {
  95. created = false;
  96. Console.WriteLine($"{creator} cannot create another team!");
  97. return created;
  98. }
  99. }
  100. return created;
  101.  
  102. }
  103. public class Team
  104. {
  105. public Team(string creator, string teamName)
  106. {
  107. Creator = creator;
  108. TeamName = teamName;
  109. Members = new List<string>();
  110. }
  111. public string Creator { get; set; }
  112. public string TeamName { get; set; }
  113. public List<string> Members { get; set; }
  114. }
  115.  
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement