SHARE
TWEET

Untitled

a guest Jun 8th, 2018 100 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. namespace _09.TeamworkProjects
  8. {
  9.  
  10.  class Team
  11.     {
  12.         public string TeamName { get; set; }
  13.         public string Creator { get; set; }
  14.         public List<string> Members { get; set; }
  15.  
  16.     }
  17.  
  18.  
  19.     class Program
  20.     {
  21.         static void Main()
  22.         {
  23.             List<Team> team = new List<Team>();
  24.             team = TeamCreator();
  25.             AddingMembers(team);
  26.             Print(team);
  27.  
  28.         }
  29.  
  30.         static List<Team> TeamCreator()
  31.         {
  32.             List<Team> team = new List<Team>();
  33.            
  34.             int numbersOfTeams = int.Parse(Console.ReadLine());
  35.  
  36.             for(int i = 0; i < numbersOfTeams; i++)
  37.             {
  38.                 string[] currentTeamData = Console.ReadLine().Split('-').ToArray();
  39.                 string currentCreator = currentTeamData[0];
  40.                 string currentTeam = currentTeamData[1];
  41.  
  42.                 if(!team.Any(x => x.TeamName.Equals(currentTeam)) && !team.Any(x => x.Creator.Equals(currentCreator)))
  43.                 {
  44.                     var newTeam = new Team
  45.                     {
  46.                         TeamName = currentTeam,
  47.                         Creator = currentCreator,
  48.                         Members = new List<string>()
  49.                     };
  50.  
  51.                     team.Add(newTeam);
  52.  
  53.                     Console.WriteLine($"Team {currentTeam} has been created by {currentCreator}!");
  54.  
  55.                 }
  56.                 else if(team.Any(x => x.TeamName.Equals(currentTeam)))
  57.                 {
  58.                     Console.WriteLine($"Team {currentTeam} was already created!");
  59.                 }
  60.                 else if(team.Any(x => x.Creator.Equals(currentCreator)))
  61.                 {
  62.                     Console.WriteLine($"{currentCreator} cannot create another team!");
  63.                 }
  64.                
  65.             }
  66.  
  67.             return team;
  68.         }
  69.  
  70.         static void AddingMembers(List<Team> team)
  71.         {
  72.             string membersInput = Console.ReadLine();
  73.  
  74.             while(membersInput != "end of assignment")
  75.             {
  76.                 string[] candidatMemberTeam = membersInput.Split(new char[] { '-', '>'}, StringSplitOptions.RemoveEmptyEntries).ToArray();
  77.                 string member = candidatMemberTeam[0];
  78.                 string wantedTeam = candidatMemberTeam[1];
  79.  
  80.                 if(!team.Any(x => x.TeamName.Equals(wantedTeam)))
  81.                 {
  82.                     Console.WriteLine($"Team {wantedTeam} does not exist!");
  83.                 }
  84.                 else if( team.Select(x => x.Members).Any(x => x.Contains(member)) || team.Any(x => x.Creator.Equals(member)))
  85.                 {
  86.                     Console.WriteLine($"Member {member} cannot join team {wantedTeam}!");
  87.                 }
  88.                 else
  89.                 {
  90.                     int teamIndex = team.FindIndex(x => x.TeamName == (wantedTeam));
  91.                     team[teamIndex].Members.Add(member);
  92.  
  93.                    // (team.First(x => x.TeamName.Equals(club))).Members.Add(member);
  94.                    
  95.                 }
  96.                
  97.  
  98.                 membersInput = Console.ReadLine();
  99.             }
  100.            
  101.         }
  102.  
  103.         static void Print(List<Team> team)
  104.         {
  105.  
  106.             var teamWithMembers = team.Where(x => x.Members.Count > 0).
  107.                                    OrderBy(x => x.TeamName).
  108.                                    ThenByDescending(x => x.Members.Count).
  109.                                    ToList();
  110.  
  111.             foreach (var club in teamWithMembers)
  112.             {
  113.                 var members = club.Members.OrderBy(x => x).ToList();
  114.  
  115.                 Console.WriteLine(club.TeamName);
  116.  
  117.                 Console.WriteLine("- " + club.Creator);
  118.  
  119.                 foreach (var name in members)
  120.                 {
  121.                     Console.WriteLine("-- " + name);
  122.                 }
  123.             }
  124.  
  125.             Console.WriteLine("Teams to disband:");
  126.  
  127.             var emptyTeam = team.Where(x => x.Members.Count == 0).OrderBy(x => x.TeamName).ToList();
  128.  
  129.             foreach (var club in emptyTeam)
  130.             {
  131.                 Console.WriteLine(club.TeamName);
  132.             }
  133.  
  134.         }
  135.  
  136.     }
  137.  
  138.  
  139. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top