Моля за малко помощ при задача 5. Teamwork projects
Здравейте,
Ще може ли малко помощ по задача по следната задача
Това е кода ми: https://pastebin.com/Ra0h8hpH
Благодаря предварително :)
Условието на задачата е:
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 Didi-PowerPuffsCoders Toni-Toni is the best Petq->PowerPuffsCoders Toni->Toni is the best end of assignment |
Team PowerPuffsCoders has been created by Didi! Team Toni is the best has been created by Toni! Member Toni cannot join team Toni is the best! PowerPuffsCoders - Didi -- Petq Teams to disband: Toni is the best |
Toni created a team, which he attempted to join later and this action resulted in throwing a certain message. Since nobody else tried to join his team, the team had to disband. |
3 Tatyana-CloneClub Helena-CloneClub Trifon-AiNaBira Pesho->aiNaBira Pesho->AiNaBira Tatyana->Leda PeshO->AiNaBira Cossima->CloneClub end of assignment |
Team CloneClub has been created by Tatyana! Team CloneClub was already created! Team AiNaBira has been created by Trifon! Team aiNaBira does not exist! Team Leda does not exist! AiNaBira - Trifon -- Pesho -- PeshO CloneClub - Tatyana -- Cossima Teams to disband: |
Благодаря :) Какво прави това ?
teams.Values:
teams е Dictionary<string, Team>, и съответно teams.Values връща IEnumerable<Teams> - поток от всички тиймове в речника (представете си го като колекция - напр. List<Team>).
.ForEach(Console.WriteLine)
Съкратен запис на:
.ForEach(teamName => Console.WriteLine(teamName))
Изпълнява Console.WriteLine за всеки елемент. В случая елементите са имената на тийовете (string).
@Stancheva
Преработих още малко решението, като добавих допълнителен клас, в който се съхраняват отборите заедно с допълнителната логика по менажирането им.
Може да е една идея по-сложо от нивото на модула, но е по-близо до това, което се очаква да правите по-нататък в обучението и в работата:
Благодаря много за инфорамацията. Изглежда като кодът,които написах но, ако трябва да съм честна разбрах на 30-40%