Advertisement
EmoRz

09. Teamwork Projects

Jun 13th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.87 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 Team()
  10.         {
  11.             Members = new List<string>();
  12.         }
  13.  
  14.         //public Team(string teamName, string creator, List<string> members)
  15.         //{
  16.         //    TeamName = teamName;
  17.         //    Creator = creator;
  18.         //    Members = members;
  19.         //}
  20.  
  21.         public string TeamName { get; set; }
  22.         public string Creator { get; set; }
  23.         public List<string> Members { get; set; }
  24.  
  25.     }
  26.     class Program
  27.     {
  28.  
  29.         static void Main(string[] args)
  30.         {
  31.             var numIteration = int.Parse(Console.ReadLine());
  32.  
  33.             List<Team> teams = new List<Team>();
  34.  
  35.             CreatorTeams(numIteration, teams);
  36.             JoinToTeams(teams);
  37.             //Print and order by
  38.             teams = teams.OrderByDescending(y => y.Members.Count).ThenBy(name => name.TeamName).ToList();
  39.             foreach (Team item in teams)
  40.             {
  41.                 if (item.Members.Count!=0)
  42.                 {
  43.                     Console.WriteLine(item.TeamName);
  44.                     Console.WriteLine("- "+item.Creator);
  45.                     foreach (var i in item.Members.OrderBy(x => x))
  46.                     {
  47.                         Console.WriteLine("-- " + i);
  48.                     }
  49.                 }
  50.             }
  51.             Console.WriteLine("Teams to disband:");
  52.             foreach (Team disban in teams.OrderBy(d => d.TeamName))
  53.             {
  54.                 if (disban.Members.Count == 0)
  55.                 {
  56.                     Console.WriteLine(disban.TeamName);
  57.                 }
  58.             }
  59.  
  60.         }
  61.  
  62.         private static void JoinToTeams(List<Team> teams)
  63.         {
  64.             while (true)
  65.             {
  66.                 string input = Console.ReadLine();
  67.                 if (input == "end of assignment")
  68.                 {
  69.                     break;
  70.                 }
  71.                 string[] partOfData = input.Split(new char[] {'-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  72.                 string nameJoin = partOfData[0];
  73.                 string teamJoin = partOfData[1];
  74.  
  75.                 if (teams.All(x => x.TeamName != teamJoin))
  76.                 {
  77.                     Console.WriteLine($"Team {teamJoin} does not exist!");
  78.                     continue;
  79.                 }
  80.                 if (teams.Any(x => x.Members.Contains(nameJoin) || teams.Any(c => c.Creator == nameJoin)))
  81.                 {
  82.  
  83.                     Console.WriteLine($"Member {nameJoin} cannot join team {teamJoin}!");
  84.                     continue;
  85.                 }
  86.                 int index = teams.FindIndex(x => x.TeamName == teamJoin);
  87.                 teams[index].Members.Add(nameJoin);
  88.             }
  89.         }
  90.  
  91.         private static void CreatorTeams(int n, List<Team> teams)  
  92.         {
  93.             for (int i = 0; i < n; i++)
  94.             {
  95.                 string[] input = Console.ReadLine().Split('-', StringSplitOptions.RemoveEmptyEntries);
  96.                 string name = input[0];
  97.                 string team = input[1];
  98.  
  99.                 if (teams.Any(x => x.TeamName == team ))
  100.                 {
  101.                     Console.WriteLine($"Team {team} was already created!");
  102.                     continue;
  103.                 }
  104.                 if (teams.Any(x => x.Creator == name))
  105.                 {
  106.                     Console.WriteLine($"{name} cannot create another team!");
  107.                     continue;
  108.                 }
  109.                 else
  110.                 {
  111.                     Team current = new Team();
  112.                     current.TeamName = team;
  113.                     current.Creator = name;
  114.                     teams.Add(current);
  115.                     Console.WriteLine($"Team {team} has been created by {name}!");
  116.                 }
  117.  
  118.             }
  119.         }
  120.  
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement