StoimenK

C#_Objects_and_Classes_1.5.Teamwork Projects

Feb 25th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _1._5.Teamwork_Projects
  6. {
  7.  
  8.     public class Team
  9.     {
  10.         public Team(string name, string creatorName)
  11.         {
  12.             TeamName = name;
  13.  
  14.             CreatorName = creatorName;
  15.  
  16.             Members = new List<string>();
  17.  
  18.         }
  19.  
  20.         public string TeamName { get; set; }
  21.  
  22.         public string CreatorName { get; set; }
  23.  
  24.         public List<string> Members { get; set; }
  25.     }
  26.  
  27.     public class Program
  28.     {
  29.         public static void Main()
  30.         {
  31.             int teamCount = int.Parse(Console.ReadLine());
  32.  
  33.             List<Team> allTeam = new List<Team>();
  34.  
  35.             for (int i = 0; i < teamCount; i++)
  36.             {
  37.                 string[] inputForTeam = Console.ReadLine().Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
  38.  
  39.                 string currentCreator = inputForTeam[0];
  40.                 string currentTeamNeme = inputForTeam[1];
  41.                
  42.                 bool isTeamNameExist = allTeam.Select(x => x.TeamName).Contains(currentTeamNeme);
  43.  
  44.                 bool isCreatorExist = allTeam.Any(x => x.CreatorName == currentCreator);
  45.  
  46.                 if (isTeamNameExist == false && isCreatorExist == false)
  47.                 {
  48.                     Team currentTeam = new Team(currentTeamNeme, currentCreator);
  49.  
  50.                     allTeam.Add(currentTeam);
  51.  
  52.                     Console.WriteLine("Team {0} has been created by {1}!", currentTeamNeme, currentCreator);
  53.                 }
  54.                 else if (isTeamNameExist)
  55.                 {
  56.                     Console.WriteLine("Team {0} was already created!", currentTeamNeme);
  57.                 }
  58.                 else if (isCreatorExist)
  59.                 {
  60.                     Console.WriteLine("{0} cannot create another team!", currentCreator);
  61.                 }
  62.             }
  63.  
  64.             while (true)
  65.             {
  66.                 string fensForTeam = Console.ReadLine();
  67.  
  68.                 if (fensForTeam == "end of assignment")
  69.                 {
  70.                     break;
  71.                 }
  72.  
  73.                 string[] inputAssignment = fensForTeam.Split(new[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  74.  
  75.                 string fen = inputAssignment[0];
  76.  
  77.                 string ofFensTeam = inputAssignment[1];
  78.  
  79.                 bool isTeamExist = allTeam.Any(x => x.TeamName == ofFensTeam);
  80.  
  81.                 bool isCreatorCheating = allTeam.Any(x => x.CreatorName == fen);
  82.                 bool isAlreadyFen = allTeam.Any(x => x.Members.Contains(fen));
  83.  
  84.                 if (isTeamExist && isCreatorCheating == false && isAlreadyFen == false)
  85.                 {
  86.                     int indexOfTeam = allTeam.FindIndex(x => x.TeamName == ofFensTeam);
  87.  
  88.                     allTeam[indexOfTeam].Members.Add(fen);
  89.                 }
  90.                 else if (isTeamExist == false)
  91.                 {
  92.                     Console.WriteLine("Team {0} does not exist!", ofFensTeam);
  93.                 }
  94.                 else if (isAlreadyFen || isCreatorCheating)
  95.                 {
  96.                     Console.WriteLine("Member {0} cannot join team {1}!", fen, ofFensTeam);
  97.                 }
  98.             }
  99.  
  100.             List<Team> teamWithMember = allTeam.Where(x => x.Members.Count > 0).OrderByDescending(x => x.Members.Count).ThenBy(x => x.TeamName).ToList();
  101.  
  102.             List<Team> notValidTeam = allTeam.Where(x => x.Members.Count == 0).OrderBy(x => x.TeamName).ToList();
  103.  
  104.             foreach (var team in teamWithMember)
  105.             {
  106.                 Console.WriteLine(team.TeamName);
  107.                 Console.WriteLine("- " + team.CreatorName);
  108.                 team.Members.Sort();
  109.                 Console.WriteLine(string.Join(Environment.NewLine, team.Members.Select(x => "-- " + x)));
  110.             }
  111.  
  112.             Console.WriteLine("Teams to disband:");
  113.  
  114.             foreach (var team in notValidTeam)
  115.             {
  116.                 Console.WriteLine(team.TeamName);
  117.             }
  118.         }
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment