Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace TeamworkProjects
- {
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- List<Team> teams = new List<Team>(n);
- #region Register teams
- for (int i = 0; i < n; i++)
- {
- string[] tokens = Console.ReadLine().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
- string userName = tokens[0],
- teamName = tokens[1];
- if (GetTeamIndex(teams, teamName) != -1)
- Console.WriteLine($"Team {teamName} was already created!");
- else if (GetUserIndex(teams, userName) != -1)
- Console.WriteLine($"{userName} cannot create another team!");
- else
- {
- teams.Add(new Team(teamName, userName));
- Console.WriteLine($"Team {teamName} has been created by {userName}!");
- }
- }
- #endregion
- #region Populate teams
- string input = Console.ReadLine();
- while (!input.Equals("end of assignment"))
- {
- string[] tokens = input.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
- string userName = tokens[0],
- teamName = tokens[1];
- int teamIndex;
- if ((teamIndex = GetTeamIndex(teams, teamName)) == -1)
- Console.WriteLine($"Team {teamName} does not exist!");
- else
- {
- int userIndex = GetUserIndex(teams, userName);
- if (userIndex != -1)
- Console.WriteLine($"Member {userName} cannot join team {teamName}!");
- else
- teams[teamIndex].teamMembers.Add(userName);
- }
- input = Console.ReadLine();
- }
- #endregion
- #region Print teams
- List<int> teamsToDisband = new List<int>();
- teams = teams.OrderByDescending(x => x.teamMembers.Count).ThenBy(x => x.teamName).ToList();
- for (int i = 0; i < teams.Count; i++)
- {
- if (teams[i].teamMembers.Count > 0)
- Console.WriteLine($"{teams[i].teamName}\n- {teams[i].teamCreator}\n-- {string.Join("\n-- ", teams[i].teamMembers)}");
- else
- teamsToDisband.Add(i);
- }
- Console.WriteLine($"Teams to disband:");
- for (int i = 0; i < teamsToDisband.Count; i++)
- Console.WriteLine($"{teams[teamsToDisband[i]].teamName}");
- #endregion
- }
- private static int GetTeamIndex(List<Team> teams, string teamName)
- {
- for (int i = 0; i < teams.Count; i++)
- if (teams[i].teamName.Equals(teamName))
- return i;
- return -1;
- }
- private static int GetUserIndex(List<Team> teams, string userName)
- {
- for (int i = 0; i < teams.Count; i++)
- if (teams[i].teamMembers.Contains(userName) || teams[i].teamCreator.Equals(userName))
- return i;
- return -1;
- }
- private class Team
- {
- public string teamName { get; set; }
- public string teamCreator { get; set; }
- public SortedSet<string> teamMembers;
- public Team(string team, string user)
- {
- this.teamName = team;
- this.teamCreator = user;
- teamMembers = new SortedSet<string>();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement