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.Runtime.InteropServices;
- using System.Text;
- using System.Numerics;
- namespace ConsoleApp7
- {
- class Program
- {
- static void Main()
- {
- int numTeams = int.Parse(Console.ReadLine());
- List<Teams> teams = new List<Teams>();
- var sb = new StringBuilder();
- var sb2 = new StringBuilder();
- sb2.AppendLine("Teams to disband:");
- for (int i = 0; i < numTeams; i++)
- {
- string[] input = Console.ReadLine().Split('-');
- string teamCreator = input[0];
- string teamName = input[1];
- if (teams.Any(x => x.Name == teamName) ) {
- sb.AppendLine($"Team {teamName} was already created!");
- }
- else if (teams.Any(x => x.Creator == teamCreator))
- {
- sb.AppendLine($"{teamCreator} cannot create another team!");
- }
- else
- {
- Teams team = new Teams(teamName, teamCreator);
- teams.Add(team);
- sb.AppendLine($"Team {teamName} has been created by {teamCreator}!");
- }
- }
- string input01;
- while ((input01 = Console.ReadLine()) != "end of assignment")
- {
- string[] inputData = input01.Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
- string memberName = inputData[0];
- string teamToJoin = inputData[1];
- if (!teams.Any(x => x.Name == teamToJoin))
- {
- sb.AppendLine($"Team {teamToJoin} does not exist!");
- }
- else if (teams.Any(team => team.Members.Contains(memberName) || team.Creator == memberName))
- {
- sb.AppendLine($"Member {memberName} cannot join team {teamToJoin}!");
- }
- else
- {
- Teams team = teams.First(t => t.Name == teamToJoin);
- team.AddMember(memberName);
- }
- }
- teams.Where(x => x.Members.Count == 0).OrderBy(x => x.Name).ToList().ForEach(x => sb2.AppendLine(x.Name));
- foreach (var team in teams.Where(x => x.Members.Count != 0).OrderByDescending(x => x.Members.Count).ThenBy(team => team.Name))
- {
- sb.AppendLine(team.Name);
- sb.AppendLine($"- {team.Creator}");
- foreach (string member in team.Members.OrderBy(x => x))
- {
- sb.AppendLine($"-- {member}");
- }
- }
- Console.WriteLine(sb.ToString().Trim());
- Console.WriteLine(sb2.ToString().Trim());
- }
- }
- class Teams
- {
- public string Name;
- public string Creator;
- public List<string> Members = new List<string>();
- public Teams(string name, string creator)
- {
- this.Name = name;
- this.Creator = creator;
- }
- public void AddMember(string member)
- {
- Members.Add(member);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement