Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _08.Mentor_Group
- {
- class Team
- {
- public string nameTeam { get; set; }
- public List<string> people { get; set; }
- public string nameCreator { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- Team firstPlayer = new Team();
- Dictionary<string, string> leadersAndTeams = new Dictionary<string, string>();
- Dictionary<string, List<string>> teamMates = new Dictionary<string, List<string>>();
- for (int i = 0; i < count; i++)
- {
- string[] inputTeams = Console.ReadLine().Split('-').ToArray();
- string leader = inputTeams[0];
- string team = inputTeams[1];
- if (leadersAndTeams.ContainsValue(team))
- {
- Console.WriteLine($"Team {team} was already created!");
- }
- if (leadersAndTeams.ContainsKey(leader))
- {
- Console.WriteLine($"{leader} cannot create another team!");
- }
- if (!leadersAndTeams.ContainsKey(leader))
- {
- leadersAndTeams.Add(leader, team);
- Console.WriteLine($"Team {team} has been created by {leader}!");
- }
- firstPlayer.nameCreator = leader;
- firstPlayer.nameTeam = team;
- }
- firstPlayer.people = new List<string>();
- //after input
- string[] playersAndTeams = Console.ReadLine().Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
- while (playersAndTeams[0] != "end of assignment")
- {
- string namePlayer = playersAndTeams[0];
- string teamToJoin = playersAndTeams[1];
- if (leadersAndTeams.ContainsValue(teamToJoin))
- {
- firstPlayer.nameTeam = teamToJoin;
- firstPlayer.people.Add(namePlayer);
- if (!teamMates.ContainsKey(teamToJoin))
- {
- teamMates.Add(teamToJoin, new List<string>());
- teamMates[teamToJoin].Add(namePlayer);
- }
- else
- {
- teamMates[teamToJoin].Add(namePlayer);
- }
- }
- else
- {
- Console.WriteLine($"Team {teamToJoin} does not exist!");
- }
- playersAndTeams = Console.ReadLine().Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
- }
- // output
- foreach (var item in leadersAndTeams)
- {
- Console.WriteLine(item.Value);
- Console.WriteLine($"- {item.Key}");
- foreach (var mates in teamMates)
- {
- if (mates.Value.Count > 0)
- {
- Console.WriteLine($"-- {string.Join(Environment.NewLine,mates.Value)}");
- }
- }
- }
- foreach (var item in teamMates)
- {
- if (item.Value.Count == 0)
- {
- Console.WriteLine("Teams to disband:");
- Console.WriteLine(item.Key);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment