Advertisement
Guest User

Solution_Teams_09

a guest
Oct 16th, 2016
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 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 _09.TeamworkProjectsList
  8. {
  9. class Team
  10. {
  11. public string ImeNaEkip { get; set; }
  12. public string Syzdatel { get; set; }
  13. public List<string> Uchastnici { get; set; }
  14.  
  15. public Team()
  16. {
  17. Uchastnici = new List<string>();
  18. }
  19. }
  20.  
  21. class TeamworkProjectList
  22. {
  23. static void Main(string[] args)
  24. {
  25. int teamsNumber = int.Parse(Console.ReadLine());
  26. List<Team> teams = new List<Team>();
  27.  
  28. CreatingTeams(teamsNumber, teams);
  29. UsersJoiningTeams(teams);
  30. PrintingTeams(teams);
  31. }
  32.  
  33. private static void CreatingTeams(int teamsNumber, List<Team> teams)
  34. {
  35. for (int i = 0; i < teamsNumber; i++)
  36. {
  37. string[] input = Console.ReadLine().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
  38. string creator = input[0];
  39. string teamName = input[1];
  40.  
  41. if (teams.Any(x => x.ImeNaEkip == teamName))
  42. {
  43. Console.WriteLine($"Team {teamName} was already created!");
  44. continue;
  45. }
  46. else if (teams.Any(x => x.Syzdatel == creator))
  47. {
  48. Console.WriteLine("{0} cannot create another team!", creator);
  49. continue;
  50. }
  51. else
  52. {
  53. Team nastoyashtEkip = new Team();
  54. nastoyashtEkip.Syzdatel = creator;
  55. nastoyashtEkip.ImeNaEkip = teamName;
  56.  
  57. teams.Add(nastoyashtEkip);
  58. Console.WriteLine("Team {0} has been created by {1}!", teamName, creator);
  59. }
  60. }
  61. }
  62.  
  63. private static void UsersJoiningTeams(List<Team> teams)
  64. {
  65. while (true)
  66. {
  67. string input = Console.ReadLine();
  68. if (input.ToLower() == "end of assignment") break;
  69.  
  70. string[] inputArgs = input.Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  71. string userToJoin = inputArgs[0];
  72. string teamToJoin = inputArgs[1];
  73.  
  74. if (teams.All(x => x.ImeNaEkip != teamToJoin))
  75. {
  76. Console.WriteLine("Team {0} does not exist!", teamToJoin);
  77. continue;
  78. }
  79.  
  80. if (teams.Any(x => x.Uchastnici.Contains(userToJoin)) || teams.Any(x => x.Syzdatel == userToJoin))
  81. {
  82. Console.WriteLine("Member {0} cannot join team {1}!", userToJoin, teamToJoin);
  83. continue;
  84. }
  85.  
  86. int teamToJoinIndex = teams.FindIndex(x => x.ImeNaEkip == teamToJoin);
  87. teams[teamToJoinIndex].Uchastnici.Add(userToJoin);
  88. }
  89. }
  90.  
  91. private static void PrintingTeams(List<Team> teams)
  92. {
  93. teams = teams.OrderByDescending(x => x.Uchastnici.Count).ThenBy(x => x.ImeNaEkip).ToList();
  94.  
  95. foreach (Team currentTeam in teams)
  96. {
  97. if (currentTeam.Uchastnici.Count != 0)
  98. {
  99. Console.WriteLine("{0}", currentTeam.ImeNaEkip);
  100. Console.WriteLine("- {0}", currentTeam.Syzdatel);
  101. foreach (string currentUser in currentTeam.Uchastnici.OrderBy(x => x))
  102. Console.WriteLine("-- {0}", currentUser);
  103. }
  104. }
  105.  
  106. Console.WriteLine("Teams to disband:");
  107. foreach (Team currentTeam in teams.OrderBy(x => x.ImeNaEkip))
  108. {
  109. if (currentTeam.Uchastnici.Count == 0)
  110. Console.WriteLine("{0}", currentTeam.ImeNaEkip);
  111. }
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement