Advertisement
Guest User

Untitled

a guest
Oct 17th, 2016
211
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class TeamworkProjects
  8. {
  9.     static void Main()
  10.     {
  11.         int teamsCount = int.Parse(Console.ReadLine());
  12.         List<Team> teams = Team.CreateTeams(teamsCount);
  13.         Team.AddMembersToTeams(teams);
  14.         List<Team> teamsToDisband = new List<Team>();
  15.         Team.PrintTeams(teams, teamsToDisband);
  16.     }
  17. }
  18.  
  19. class Team
  20. {
  21.     public string Name { get; set; }
  22.     public string Creator { get; set; }
  23.     public List<string> Members { get; set; }
  24.  
  25.     public static List<Team> CreateTeams(int teamsCount)
  26.     {
  27.         List<Team> teams = new List<Team>();
  28.  
  29.         for (int i = 0; i < teamsCount; i++)
  30.         {
  31.             string[] teamArgs = Console.ReadLine().Split('-');
  32.             string teamCreator = teamArgs[0];
  33.             string teamName = teamArgs[1];
  34.             if (teams.Any(t => t.Name == teamName))
  35.             {
  36.                 Console.WriteLine($"Team {teamName} was already created!");
  37.             }
  38.             else if (teams.Any(t => t.Creator == teamCreator))
  39.             {
  40.                 Console.WriteLine($"{teamCreator} cannot create another team!");
  41.             }
  42.             else
  43.             {
  44.                 Team currentTeam = new Team();
  45.                 currentTeam.Name = teamName;
  46.                 currentTeam.Creator = teamCreator;
  47.                 currentTeam.Members = new List<string>();
  48.                 currentTeam.Members.Add(teamCreator);
  49.                 teams.Add(currentTeam);
  50.                 Console.WriteLine($"Team {currentTeam.Name} has been created by {currentTeam.Creator}!");
  51.             }
  52.  
  53.         }
  54.         return teams;
  55.     }
  56.  
  57.     public static void AddMembersToTeams(List<Team> teams)
  58.     {
  59.         string[] memberArgs = Console.ReadLine().Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  60.         while (!memberArgs.Contains("end of assignment"))
  61.         {
  62.             string memberName = memberArgs[0];
  63.             string memberTeam = memberArgs[1];
  64.             Team currentTeam = new Team();
  65.  
  66.             if (!teams.Any(t => t.Name == memberTeam))
  67.             {
  68.                 Console.WriteLine($"Team {memberTeam} does not exist!");
  69.             }
  70.             else
  71.             {
  72.                 bool foundMember = false;
  73.                 foreach (var team in teams)
  74.                 {
  75.                     if (team.Members.Any(m => m == memberName))
  76.                     {
  77.                         foundMember = true;
  78.                         Console.WriteLine($"Member {memberName} cannot join team {team.Name}!");
  79.                         break;
  80.                     }
  81.                 }
  82.                 if (!foundMember)
  83.                 {
  84.                     currentTeam = teams.First(t => t.Name == memberTeam);
  85.                     currentTeam.Members.Add(memberName);
  86.                 }
  87.             }
  88.             memberArgs = Console.ReadLine().Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  89.         }
  90.     }
  91.  
  92.     public static void PrintTeams(List<Team> teams, List<Team> teamsToDisband)
  93.     {
  94.         foreach (var team in teams.OrderByDescending(t => t.Members.Count).ThenBy(t => t.Creator))
  95.         {
  96.             //Team currentTeam = team;
  97.             team.Members.RemoveAt(0);
  98.             if (team.Members.Count == 0)
  99.             {
  100.                 teamsToDisband.Add(team);
  101.                 continue;
  102.             }
  103.  
  104.             Console.WriteLine($"{team.Name}");
  105.             Console.WriteLine($"- {team.Creator}");
  106.             foreach (var member in team.Members.OrderBy(n => n))
  107.             {
  108.                 Console.WriteLine($"-- {member}");
  109.             }
  110.         }
  111.  
  112.         //print dissolute teams
  113.         Console.WriteLine("Teams to disband:");
  114.         foreach (var team in teamsToDisband.OrderBy(t => t.Name))
  115.         {
  116.             Console.WriteLine($"{team.Name}");
  117.         }
  118.     }
  119. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement