Guest User

Untitled

a guest
Jan 9th, 2018
388
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. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class Program
  9. {
  10. static void Main()
  11. {
  12. int numberOfIterations = int.Parse(Console.ReadLine());
  13. List<Team> listOfTeams = GetListOfTeams(numberOfIterations);
  14. listOfTeams = AddMembers(listOfTeams);
  15. var orderedList = GetOrderedList(listOfTeams);
  16. PrintRealTeams(orderedList);
  17. //Console.WriteLine();
  18. }
  19.  
  20. static void PrintRealTeams(List<Team> orderedList)
  21. {
  22. foreach (var team in orderedList.Where(m => m.TeamMembers.Count > 0))
  23. {
  24. Console.WriteLine($"{team.TeamName}");
  25. Console.WriteLine($"- {team.TeamCreator}");
  26. foreach (var tm in team.TeamMembers.OrderBy(n=>n))
  27. {
  28. Console.WriteLine($"-- {tm}");
  29. }
  30. }
  31. Console.WriteLine($"Teams to disband:");
  32. foreach (var team in orderedList.Where(m => m.TeamMembers.Count == 0))
  33. {
  34. Console.WriteLine($"{team.TeamName}");
  35. }
  36. }
  37.  
  38. static List<Team> GetOrderedList(List<Team> listOfTeams)
  39. {
  40. return listOfTeams.OrderByDescending(a => a.TeamMembers.Count).ThenBy(n => n.TeamName).ToList();
  41. }
  42.  
  43. static List<Team> AddMembers(List<Team> listOfTeams)
  44. {
  45. while (true)
  46. {
  47. var inputLine = Console.ReadLine();
  48. if (inputLine == "end of assignment")
  49. break;
  50. string[] separator = new string[] { "->" };
  51. var currentLine = inputLine.Split(separator, StringSplitOptions.None).ToList();
  52. var memberName = currentLine.First();
  53. var clubName = currentLine.Last();
  54. var currentTeam = listOfTeams.FirstOrDefault(n => n.TeamName == clubName);
  55. if (!listOfTeams.Any(t => t.TeamName == clubName))
  56. {
  57. Console.WriteLine($"Team {clubName} does not exist!");
  58. continue;
  59. }
  60. else if (listOfTeams.Any(n => n.TeamMembers.Contains(memberName))
  61. || listOfTeams.Any(cr => cr.TeamCreator == memberName))
  62. {
  63. Console.WriteLine($"Member {memberName} cannot join team {clubName}!");
  64. continue;
  65. }
  66. else
  67. {
  68. currentTeam.TeamMembers.Add(memberName);
  69. }
  70. }
  71. return listOfTeams;
  72. }
  73.  
  74. static List<Team> GetListOfTeams(int numberOfIterations)
  75. {
  76. var listOfTeams = new List<Team>();
  77. for (int i = 0; i < numberOfIterations; i++)
  78. {
  79. var currentline = Console.ReadLine().Split('-').ToList();
  80. var creatorName = currentline.First();
  81. var teamName = currentline.Last();
  82.  
  83. if (listOfTeams.Any(n => n.TeamName == teamName))
  84. {
  85. Console.WriteLine($"Team {teamName} was already created!");
  86. continue;
  87. }
  88. else if (listOfTeams.Any(c => c.TeamCreator == creatorName))
  89. {
  90. Console.WriteLine($"{creatorName} cannot create another team!");
  91. continue;
  92. }
  93. else
  94. {
  95. var newTeam = new Team
  96. {
  97. TeamName = teamName,
  98. TeamCreator = creatorName,
  99. TeamMembers = new List<string>()
  100. };
  101. Console.WriteLine($"Team {teamName} has been created by {creatorName}!");
  102. listOfTeams.Add(newTeam);
  103. }
  104.  
  105. }
  106. return listOfTeams;
  107. }
  108. }
  109.  
  110. class Team
  111. {
  112. public string TeamName { get; set; }
  113.  
  114. public string TeamCreator { get; set; }
  115.  
  116. public List<string> TeamMembers { get; set; }
  117. }
RAW Paste Data