Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- namespace ExamPreparation
- {
- public sealed class Team
- {
- public Team(string creator, string teamName)
- {
- this.Creator = creator;
- this.TeamName = teamName;
- this.Members = new SortedSet<string>();
- }
- public string Creator { get; private set; }
- public string TeamName { get; private set; }
- public SortedSet<string> Members { get; set; }
- public override string ToString()
- {
- StringBuilder output = new StringBuilder();
- if (this.Members.Any())
- {
- output.AppendLine(this.TeamName);
- output.AppendLine($"- {this.Creator}");
- foreach (var member in this.Members)
- {
- output.AppendLine($"-- {member}");
- }
- }
- else
- {
- output.Append(this.TeamName);
- }
- return output.ToString().Trim();
- }
- }
- public sealed class Preparation
- {
- public static void Main()
- {
- int teamsCount = int.Parse(Console.ReadLine());
- Dictionary<string, Team> teams = new Dictionary<string, Team>();
- for (int i = 0; i < teamsCount; i++)
- {
- string[] tokens = Console.ReadLine().Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
- string creator = tokens[0];
- string teamName = tokens[1];
- if (teams.ContainsKey(teamName))
- {
- Console.WriteLine($"Team {teamName} was already created!");
- }
- else if (teams.Any(x => x.Value.Creator == creator))
- {
- Console.WriteLine($"{creator} cannot create another team!");
- }
- else
- {
- teams.Add(teamName, new Team(creator, teamName));
- Console.WriteLine($"Team {teamName} has been created by {creator}!");
- }
- }
- string input = Console.ReadLine();
- while (input != "end of assignment")
- {
- string[] tokens = input.Split(new[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
- string user = tokens[0];
- string teamName = tokens[1];
- if (teams.ContainsKey(teamName))
- {
- if (teams.Values.Any(x => x.Members.Contains(user)) || teams.Any(x => x.Value.Creator == user))
- {
- Console.WriteLine($"Member {user} cannot join team {teamName}!");
- }
- else
- {
- teams[teamName].Members.Add(user);
- }
- }
- else
- {
- Console.WriteLine($"Team {teamName} does not exist!");
- }
- input = Console.ReadLine();
- }
- foreach (var team in teams.Where(x => x.Value.Members.Any()).OrderByDescending(x => x.Value.Members.Count).ThenBy(x => x.Value.TeamName))
- {
- Console.WriteLine(team.Value);
- }
- Console.WriteLine("Teams to disband:");
- foreach (var team in teams.Where(x => x.Value.Members.Count == 0).OrderBy(x => x.Value.TeamName))
- {
- Console.WriteLine(team.Value);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment