Advertisement
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 Teamwork_project
- {
- class Team
- {
- public string Name { get; set; }
- public string CreatorTeamName { get; set; }
- public List<string> users { get; set; }
- }
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- List<Team> teamList = new List<Team>();
- List<string> messages = new List<string>();
- string[] inputArr;
- string nameUser = null;
- string input = null;
- string nameTeam = null;
- string messageStr = null;
- for (int i = 0; i < n; i++)
- {
- input = Console.ReadLine();
- inputArr = input.Trim().Split('-');
- nameUser = inputArr[0];
- nameTeam = inputArr[1];
- if ((!teamList.Any(x => x.Name == nameTeam)) &&
- (!teamList.Any(x => x.CreatorTeamName == nameUser)))
- {
- Team team = new Team();
- team.users = new List<string>();
- team.CreatorTeamName = nameUser;
- team.Name = nameTeam;
- teamList.Add(team);
- messageStr = "Team " + nameTeam + " has been created by " + nameUser + "!";
- messages.Add(messageStr);
- }
- else
- {
- if (teamList.Any(x => x.Name == nameTeam))
- {
- messageStr = "Team " + nameTeam + " was already created!";
- messages.Add(messageStr);
- }
- if (teamList.Any(x => x.CreatorTeamName == nameUser))
- {
- messageStr = nameUser + " cannot create another team!";
- messages.Add(messageStr);
- }
- }
- }
- do
- {
- input = Console.ReadLine();
- if (input== "end of assignment")
- {
- break;
- }
- inputArr = input
- .Trim()
- .Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
- nameUser = inputArr[0];
- nameTeam = inputArr[1];
- if (!teamList.Any(x => x.Name == nameTeam))
- {
- messageStr = "Team " + nameTeam + " does not exist!";
- messages.Add(messageStr);
- }
- else
- {
- if ((teamList.Any(x => x.users.Contains(nameUser))) ||
- (teamList.Any(x => x.CreatorTeamName == nameUser)))
- {
- messageStr = "Member " + nameUser + " cannot join team " + nameTeam + "!";
- messages.Add(messageStr);
- }
- else
- {
- int index = teamList.FindIndex(x => x.Name == nameTeam);
- teamList[index].users.Add(nameUser);
- }
- }
- } while (input != "end of assignment");
- foreach (var message in messages)
- {
- Console.WriteLine(message);
- }
- var sortTeamList = teamList.OrderByDescending(x => x.users.Count).OrderBy(x => x.Name);
- List<string> disbandList = new List<string>();
- foreach (var team in sortTeamList)
- {
- if (team.users.Count > 0)
- {
- Console.WriteLine(team.Name);
- Console.WriteLine("- {0}", team.CreatorTeamName);
- var sortUsersName = team.users.OrderBy(x => x).ToList();
- for (int i = 0; i < sortUsersName.Count; i++)
- {
- Console.WriteLine("-- {0}",sortUsersName[i]);
- }
- }
- else
- {
- disbandList.Add(team.Name);
- }
- }
- Console.WriteLine("Teams to disband:");
- if (disbandList.Count > 0)
- {
- var sortDisbandList = disbandList.OrderBy(x => x);
- foreach (var sdl in sortDisbandList)
- {
- Console.WriteLine(sdl);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement