Guest User

Untitled

a guest
Mar 24th, 2019
393
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem05TeamworkProjects
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int numberOfTeams = int.Parse(Console.ReadLine());
  12.  
  13. List<Team> teams = new List<Team>();
  14.  
  15. for (int i = 1; i <= numberOfTeams; i++)
  16. {
  17. string[] line = Console.ReadLine().Split('-');
  18. var currentTeam = new Team();
  19.  
  20. string creator = line[0];
  21. string teamName = line[1];
  22.  
  23. currentTeam.Creator = creator;
  24. currentTeam.Name = teamName;
  25.  
  26. if (teams.Any(x => x.Name == teamName))
  27. {
  28. Console.WriteLine($"Team {teamName} was already created!");
  29. continue;
  30. }
  31.  
  32. if (teams.Any(x => x.Creator == creator))
  33. {
  34. Console.WriteLine($"{creator} cannot create another team!");
  35. continue;
  36. }
  37.  
  38. teams.Add(currentTeam);
  39. Console.WriteLine($"Team {teamName} has been created by {creator}!");
  40. }
  41.  
  42. while (true)
  43. {
  44. string currentCommand = Console.ReadLine();
  45.  
  46. if (currentCommand == "end of assignment")
  47. {
  48. break;
  49. }
  50.  
  51. string[] line = currentCommand.Split("->");
  52.  
  53. string user = line[0];
  54. string team = line[1];
  55.  
  56. if (!teams.Any(x => x.Name == team))
  57. {
  58. Console.WriteLine($"Team {team} does not exist!");
  59. continue;
  60. }
  61.  
  62. if (teams.Any(x => x.Creator == user) || teams.Any(x => x.Members.Contains(user)))
  63. {
  64. Console.WriteLine($"Member {user} cannot join team {team}!");
  65. continue;
  66. }
  67.  
  68. if (teams.Any(x => x.Name == team))
  69. {
  70. var existingTeam = teams.First(x => x.Name == team);
  71.  
  72. existingTeam.Members.Add(user);
  73. }
  74. }
  75.  
  76. var teamsDisband = teams.Where(x => x.Members.Count == 0).Select(x => x.Name).ToList();
  77.  
  78. foreach (var team in teams.OrderByDescending(x => x.Members.Count).ThenBy(x => x.Name))
  79. {
  80. if (team.Members.Count == 0)
  81. {
  82. continue;
  83. }
  84.  
  85. Console.WriteLine($"{team.Name}");
  86. Console.WriteLine($"- {team.Creator}");
  87.  
  88. foreach (var name in team.Members.OrderBy(x => x))
  89. {
  90. Console.WriteLine($"-- {name}");
  91. }
  92. }
  93.  
  94. Console.WriteLine("Teams to disband:");
  95. foreach (var item in teamsDisband.OrderBy(x => x))
  96. {
  97. Console.WriteLine(item);
  98. }
  99. }
  100. }
  101.  
  102. class Team
  103. {
  104. public string Name;
  105. public string Creator;
  106. public List<string> Members = new List<string>();
  107. }
  108. }
RAW Paste Data