Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- public class Soft
- {
- public static void Main()
- {
- List<Team> TeamList = new List<Team>();
- int n = int.Parse(Console.ReadLine());
- string name;
- string teamName;
- for(int i=0;i<n;i++)
- {
- string[] input = Console.ReadLine().Split('-').ToArray();
- name = input[0];
- teamName = input[1];
- if (TeamList.Any(x=> x.TeamName==teamName))
- {
- Console.WriteLine($"Team {teamName} was already created!");
- continue;
- }
- else if(TeamList.Any(x=>x.Creator==name))
- {
- Console.WriteLine($"{name} cannot create another team!");
- continue;
- }
- else
- {
- List<string> members = new List<string>();
- Team team = new Team();
- team.Creator = name;
- team.TeamName = teamName;
- team.Members = members;
- TeamList.Add(team);
- Console.WriteLine($"Team {teamName} has been created by {name}!");
- }
- }
- string input2 = Console.ReadLine();
- while(input2!= "end of assignment")
- {
- string[] input = input2.Split(new char[] { '-','>'},StringSplitOptions.RemoveEmptyEntries).ToArray();
- name = input[0];
- teamName = input[1];
- if(!TeamList.Any(x=>x.TeamName==teamName))
- {
- Console.WriteLine($"Team {teamName} does not exist!");
- input2 = Console.ReadLine();
- continue;
- }
- else if(TeamList.Any(x=>x.Members.Contains(name)))
- {
- Console.WriteLine($"Member {name} cannot join team {teamName}");
- input2 = Console.ReadLine();
- continue;
- }
- else if(TeamList.Any(x=>x.Creator==name))
- {
- Console.WriteLine($"Member {name} cannot join team {teamName}!");
- }
- else
- {
- foreach(var team in TeamList.Where(x=>x.TeamName==teamName))
- {
- team.Members.Add(name);
- }
- }
- input2 = Console.ReadLine();
- }
- List<string> disbanded = new List<string>();
- foreach(var team in TeamList.Where(x=>x.Members.Count!=0).OrderByDescending(x=>x.Members.Count).ThenBy(x=>x.TeamName))
- {
- Console.WriteLine(team.TeamName);
- Console.WriteLine($"- {team.Creator}");
- foreach(var member in team.Members.OrderBy(x=>x))
- {
- Console.WriteLine($"-- {member}");
- }
- }
- Console.WriteLine($"Teams to disband:");
- foreach (var team in TeamList.Where(x=>x.Members.Count==0).OrderBy(x=>x.TeamName))
- {
- Console.WriteLine(team.TeamName);
- }
- Console.ReadLine();
- }
- }
- public class Team
- {
- public string TeamName { get; set; }
- public List<string> Members { get; set; }
- public string Creator { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement