Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Numerics;
- using System.Collections.Generic;
- using System.Linq;
- namespace OOPBasics
- {
- class Program
- {
- public static void Project(int n)
- {
- List<Team> teams = new List<Team>();
- for (int i = 0; i < n; i++)
- {
- string[] tokens = Console.ReadLine().Split('-');
- string creator = tokens[0];
- string teamName = tokens[1];
- bool isTeamMoreThanOnce = teams.Any(t => t.TeamName == teamName);
- if (isTeamMoreThanOnce)
- {
- Console.WriteLine($"Team {teamName} was already created!");
- continue;
- }
- bool isUserHasATeam = teams.Any(c => c.Creator == creator);
- if (isUserHasATeam)
- {
- Console.WriteLine($"{creator} cannot create another team!");
- continue;
- }
- Team team = new Team(creator, teamName);
- teams.Add(team);
- Console.WriteLine($"Team {teamName} has been created by {creator}!");
- }
- while (true)
- {
- string[] tokens = Console.ReadLine().Split("->");
- if (tokens[0] == "end of assignment")
- {
- break;
- }
- string member = tokens[0];
- string teamName = tokens[1];
- bool isTeamExists = teams.Any(t => t.TeamName == teamName);
- if (isTeamExists == false)
- {
- Console.WriteLine($"Team {teamName} does not exist!");
- continue;
- }
- bool isAlreadyInATeam = teams.Any(m => m.Members.Contains(member) || m.Creator == member);
- if (isAlreadyInATeam)
- {
- Console.WriteLine($"Member {member} cannot join team {teamName}!");
- continue;
- }
- foreach (var item in teams)
- {
- if (item.TeamName == teamName)
- {
- item.Members.Add(member);
- }
- }
- }
- List<Team> disbandedTeams = teams.Where(x => x.Members.Count == 0).OrderBy(x => x.TeamName).ToList(); // no
- var sorted = teams.Where(x => x.Members.Count > 0).OrderByDescending(x => x.Members.Count).ThenBy(x => x.TeamName) // no
- .ToList();
- foreach (var item in sorted)
- {
- Console.WriteLine(item.TeamName);
- Console.WriteLine("- {0}", item.Creator);
- foreach (var member in item.Members.OrderBy(m => m))
- {
- Console.WriteLine("-- {0}", member);
- }
- }
- Console.WriteLine("Teams to disband:");
- foreach (var team in disbandedTeams)
- {
- Console.WriteLine(team.TeamName);
- }
- }
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- Project(n);
- }
- }
- public class Team
- {
- public Team(string creator, string teamName)
- {
- this.Creator = creator;
- this.TeamName = teamName;
- this.Members = new List<string>();
- }
- public string TeamName { get; set; }
- public string Creator { get; set; }
- public List<string> Members { get; set; }
- }
- } // .
Advertisement
Add Comment
Please, Sign In to add comment