Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 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.  
  8. class TeamworkProjects
  9. {
  10. static void Main()
  11. {
  12. var list = new List<Team>();
  13.  
  14. int n = int.Parse(Console.ReadLine());
  15.  
  16. RegisteringTeams(list, n);
  17. AddingTeamMembers(list);
  18. PrintingResults(list);
  19. }
  20.  
  21. private static void RegisteringTeams(List<Team> list, int n)
  22. {
  23. for (int i = 0; i < n; i++)
  24. {
  25. Team newTeam = new Team();
  26.  
  27. var str = Console.ReadLine().Split('-');
  28. var creatorName = str[0];
  29. var team = str[1];
  30.  
  31. newTeam.TeamName = team;
  32. newTeam.CreatorName = creatorName;
  33. newTeam.Members = new List<string>();
  34. if (list.Any(c => c.CreatorName == creatorName))
  35. {
  36. Console.WriteLine($"{creatorName} cannot create another team!");
  37. continue;
  38. }
  39.  
  40. if (list.Any(t => t.TeamName == team))
  41. {
  42. Console.WriteLine($"Team {team} was already created!");
  43. continue;
  44. }
  45.  
  46. Console.WriteLine($"Team {team} has been created by {creatorName}!");
  47. list.Add(newTeam);
  48. }
  49. }
  50.  
  51. private static void AddingTeamMembers(List<Team> list)
  52. {
  53. while (true)
  54. {
  55. var input = Console.ReadLine();
  56. if (input == "end of assignment") break;
  57. var split = input.Split(new char[] { '-', '>' });
  58. var user = split[0];
  59. var teamJoin = split[2];
  60.  
  61. if (!list.Any(t => t.TeamName == teamJoin))
  62. {
  63. Console.WriteLine($"Team {teamJoin} does not exist!");
  64. continue;
  65. }
  66.  
  67. if (list.Any(nz => nz.CreatorName == user))
  68. {
  69. Console.WriteLine($"Member {user} cannot join team {teamJoin}!");
  70. continue;
  71. }
  72. if (list.Any(t => t.TeamName == teamJoin))
  73. {
  74. var existingTeam = list.First(t => t.TeamName == teamJoin);
  75.  
  76. existingTeam.Members.Add(user);
  77. continue;
  78. }
  79.  
  80. }
  81. }
  82.  
  83. private static void PrintingResults(List<Team> list)
  84. {
  85. var teamsDisband = list.Where(t => t.Members.Count == 0).Select(x => x.TeamName).ToList();
  86.  
  87. foreach (var team in list.OrderByDescending(m => m.Members.Count).ThenBy(z => z.TeamName))
  88. {
  89. if (team.Members.Count == 0) continue;
  90.  
  91. Console.WriteLine(team.TeamName);
  92. Console.WriteLine($"- {team.CreatorName}");
  93.  
  94. foreach (var pl in team.Members.OrderBy(x => x))
  95. {
  96. Console.WriteLine($"-- {pl}");
  97. }
  98. }
  99. Console.WriteLine("Teams to disband:");
  100. foreach (var item in teamsDisband.OrderBy(x => x))
  101. {
  102.  
  103. Console.WriteLine(item);
  104. }
  105. }
  106. }
  107.  
  108. class Team
  109. {
  110. public string TeamName { get; set; }
  111. public List<string> Members { get; set; }
  112. public string CreatorName { get; set; }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement