Advertisement
dragonbs

Teamwork Projects

Mar 25th, 2023
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace TeamworkProjects
  6. {
  7.     class Team
  8.     {
  9.         public string TeamName { get; set; }
  10.         public string CreatorName { get; set; }
  11.         public List<string> Members { get; set; }
  12.     }
  13.     class Program
  14.     {
  15.         static void Main()
  16.         {
  17.             int teamsCount = int.Parse(Console.ReadLine());
  18.             List<Team> teams = new List<Team>();
  19.             for (int i = 0; i < teamsCount; i++)
  20.             {
  21.                 string[] newTeam = Console.ReadLine().Split('-').ToArray();
  22.                 List<string> membersList = new List<string>();
  23.                 Team team = new Team();
  24.                 team.TeamName = newTeam[1];
  25.                 team.CreatorName = newTeam[0];
  26.                 team.Members = membersList;
  27.                 if (!teams.Select(x => x.TeamName).Contains(team.TeamName))
  28.                 {
  29.                     if (!teams.Select(x => x.CreatorName).Contains(team.CreatorName))
  30.                     {
  31.                         teams.Add(team);
  32.                         Console.WriteLine("Team {0} has been created by {1}!", newTeam[1], newTeam[0]);
  33.                     }
  34.                     else
  35.                     {
  36.                         Console.WriteLine("{0} cannot create another team!", team.CreatorName);
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     Console.WriteLine("Team {0} was already created!", team.TeamName);
  42.                 }
  43.             }
  44.  
  45.             string teamRegistration = Console.ReadLine();
  46.  
  47.             while (!teamRegistration.Equals("end of assignment"))
  48.             {
  49.                 var split = teamRegistration.Split(new char[] { '-', '>' }).ToArray();
  50.                 string newUser = split[0];
  51.                 string teamName = split[2];
  52.                 if (!teams.Select(x => x.TeamName).Contains(teamName))
  53.                 {
  54.                     Console.WriteLine("Team {0} does not exist!", teamName);
  55.                 }
  56.                 else if (teams.Select(x => x.Members).Any(x => x.Contains(newUser)) || teams.Select(x => x.CreatorName).Contains(newUser))
  57.                 {
  58.                     Console.WriteLine("Member {0} cannot join team {1}!", newUser, teamName);
  59.                 }
  60.                 else
  61.                 {
  62.                     int teamToJoinIndex = teams.FindIndex(x => x.TeamName == teamName);
  63.                     teams[teamToJoinIndex].Members.Add(newUser);
  64.                 }
  65.  
  66.                 teamRegistration = Console.ReadLine();
  67.             }
  68.  
  69.             var teamsToDisband = teams.OrderBy(x => x.TeamName).Where(x => x.Members.Count == 0);
  70.             var fullTeams = teams.
  71.             OrderByDescending(x => x.Members.Count).
  72.             ThenBy(x => x.TeamName).
  73.             Where(x => x.Members.Count > 0);
  74.  
  75.             foreach (var team in fullTeams)
  76.             {
  77.                 Console.WriteLine($"{team.TeamName}");
  78.                 Console.WriteLine($"- {team.CreatorName}");
  79.                 foreach (var member in team.Members.OrderBy(x => x))
  80.                 {
  81.                     Console.WriteLine($"-- {member}");
  82.                 }
  83.             }
  84.  
  85.             Console.WriteLine("Teams to disband:");
  86.             foreach (var item in teamsToDisband)
  87.             {
  88.                 Console.WriteLine(item.TeamName);
  89.             }
  90.  
  91.         }
  92.     }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement