Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 13.ObjectAndClasses-Teamwork projects
- It's time for the teamwork projects and you are responsible for gathering the teams. First you will receive an integer - the count of the teams you will have to register. You will be given a user and a team, separated with “-”. The user is the creator of the team. For every newly created team you should print a message:
- "Team {teamName} has been created by {user}!".
- Next, you will receive an user with a team, separated with "->", which means that the user wants to join that team. Upon receiving the command: “end of assignment”, you should print every team, ordered by the count of its members (descending) and then by name (ascending). For each team, you have to print its members sorted by name (ascending). However, there are several rules:
- • If an user tries to create a team more than once, a message should be displayed:
- - "Team {teamName} was already created!"
- • A creator of a team cannot create another team – the following message should be thrown:
- - "{user} cannot create another team!"
- • If an user tries to join a non-existent team, a message should be displayed:
- - "Team {teamName} does not exist!"
- • A member of a team cannot join another team – the following message should be thrown:
- - "Member {user} cannot join team {team Name}!"
- • In the end, teams with zero members (with only a creator) should disband and you have to print them ordered by name in ascending order.
- • Every valid team should be printed ordered by name (ascending) in the following format:
- "{teamName}:
- - {creator}
- -- {member}…"
- Examples
- Input Output Comments
- 2 Team PowerPuffsCoders has been created by Didi! Toni created a team, which he attempted to join later and
- Didi-PowerPuffsCoders Team Toni is the best has been created by Toni! this action resulted in throwing a certain message. Since
- Toni-Toni is the best Member Toni cannot join team Toni is the best! nobody else tried to join his team, the team had to disband.
- Petq->PowerPuffsCoders PowerPuffsCoders
- Toni->Toni is the best - Didi
- end of assignment -- Petq
- Teams to disband:
- Toni is the best
- 3
- Tatyana-CloneClub Team CloneClub has been created by Tatyana! Note that when a user joins a team, you should first
- Helena-CloneClub Team CloneClub was already created! check if the team exists and then check
- Trifon-AiNaBira Team AiNaBira has been created by Trifon! if the user is already in a team:
- Pesho->aiNaBira Team aiNaBira does not exist! Tatyana has created CloneClub, then she tried to join
- Pesho->AiNaBira Team Leda does not exist! a non-existent team and the concrete message was displayed.
- Tatyana->Leda AiNaBira
- PeshO->AiNaBira - Trifon
- Cossima->CloneClub -- Pesho
- end of assignment -- PeshO
- CloneClub
- - Tatyana
- -- Cossima
- Teams to disband:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem05TeamworkProjects
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfTeams = int.Parse(Console.ReadLine());
- List<Team> teams = new List<Team>();
- for (int i = 1; i <= numberOfTeams; i++)
- {
- string[] line = Console.ReadLine().Split('-');
- var currentTeam = new Team();
- string creator = line[0];
- string teamName = line[1];
- currentTeam.Creator = creator;
- currentTeam.Name = teamName;
- if (teams.Any(x => x.Name == teamName))
- {
- Console.WriteLine($"Team {teamName} was already created!");
- continue;
- }
- if (teams.Any(x => x.Creator == creator))
- {
- Console.WriteLine($"{creator} cannot create another team!");
- continue;
- }
- teams.Add(currentTeam);
- Console.WriteLine($"Team {teamName} has been created by {creator}!");
- }
- while (true)
- {
- string currentCommand = Console.ReadLine();
- if (currentCommand == "end of assignment")
- {
- break;
- }
- string[] line = currentCommand.Split("->");
- string user = line[0];
- string team = line[1];
- if (!teams.Any(x => x.Name == team))
- {
- Console.WriteLine($"Team {team} does not exist!");
- continue;
- }
- if (teams.Any(x => x.Creator == user) || teams.Any(x => x.Members.Contains(user)))
- {
- Console.WriteLine($"Member {user} cannot join team {team}!");
- continue;
- }
- if (teams.Any(x => x.Name == team))
- {
- var existingTeam = teams.First(x => x.Name == team);
- existingTeam.Members.Add(user);
- }
- }
- var teamsDisband = teams.Where(x => x.Members.Count == 0).Select(x => x.Name).ToList();
- foreach (var team in teams.OrderByDescending(x => x.Members.Count).ThenBy(x => x.Name))
- {
- if (team.Members.Count == 0)
- {
- continue;
- }
- Console.WriteLine($"{team.Name}");
- Console.WriteLine($"- {team.Creator}");
- foreach (var name in team.Members.OrderBy(x => x))
- {
- Console.WriteLine($"-- {name}");
- }
- }
- Console.WriteLine("Teams to disband:");
- foreach (var item in teamsDisband.OrderBy(x => x))
- {
- Console.WriteLine(item);
- }
- }
- }
- class Team
- {
- public string Name;
- public string Creator;
- public List<string> Members = new List<string>();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement