deleriumbg

Teamwork Projects

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