Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;  // 100/100
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _9.Teamwork_projects
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             var teams = new List<Team>();
  14.             var joinedMembers = new List<string>();
  15.  
  16.             int nOfTeams = int.Parse(Console.ReadLine());
  17.             for (int i = 0; i < nOfTeams; i++)
  18.             {
  19.                 var tokens = Console.ReadLine().Split('-').ToArray();
  20.                 var creator = tokens[0];
  21.                 var teamToCreate = tokens[1];
  22.  
  23.                 if(teams.Any(x=>x.teamName == teamToCreate))
  24.                 {
  25.                     Console.WriteLine($"Team {teamToCreate} was already created!");
  26.                     continue;
  27.                 }
  28.  
  29.                 if (teams.Any(x => x.creatorName == creator))
  30.                 {
  31.                     Console.WriteLine($"{creator} cannot create another team!");
  32.                     continue;
  33.                 }
  34.  
  35.                 teams.Add(new Team(teamToCreate, creator));
  36.                 joinedMembers.Add(creator);
  37.                 Console.WriteLine($"Team {teamToCreate} has been created by {creator}!");
  38.             }
  39.             string input = Console.ReadLine();
  40.             while(input!= "end of assignment")
  41.             {
  42.                 var tokens = input.Split(new string[] { "->" },StringSplitOptions.None).ToArray();
  43.                 var name = tokens[0];
  44.                 var teamToJoin = tokens[1];
  45.  
  46.                 if(!teams.Any(x=>x.teamName == teamToJoin))
  47.                 {
  48.                     Console.WriteLine($"Team {teamToJoin} does not exist!");
  49.                     input = Console.ReadLine();
  50.                     continue;
  51.                 }
  52.  
  53.                 if (joinedMembers.Contains(name))
  54.                 {
  55.                     Console.WriteLine($"Member {name} cannot join team {teamToJoin}!");
  56.                     input = Console.ReadLine();
  57.                     continue;
  58.                 }
  59.  
  60.                 teams.Single(x => x.teamName == teamToJoin).teamMembers.Add(name);
  61.                 joinedMembers.Add(name);
  62.  
  63.                 input = Console.ReadLine();
  64.             }
  65.  
  66.             foreach (var team in teams.OrderByDescending(x=>x.teamMembers.Count).ThenBy(x=>x.teamName))
  67.             {
  68.                 if(team.teamMembers.Count> 0)
  69.                 {
  70.                     Console.WriteLine(team.teamName);
  71.                     Console.WriteLine("- "+team.creatorName);
  72.                     foreach (var member in team.teamMembers.OrderBy(x=>x))
  73.                     {
  74.                         Console.WriteLine("-- "+member);
  75.                     }
  76.                 }
  77.             }
  78.  
  79.             Console.WriteLine("Teams to disband:");
  80.             foreach (var item in teams.Where(x=>x.teamMembers.Count == 0).OrderBy(x=>x.teamName))
  81.             {
  82.                 Console.WriteLine(item.teamName);
  83.             }
  84.             //Console.ReadLine();
  85.         }
  86.     }
  87.  
  88.     public class Team
  89.     {
  90.         public string teamName;
  91.         public string creatorName;
  92.         public List<string> teamMembers = new List<string>();
  93.         public Team(string TeamName, string CreatorName)
  94.         {
  95.             this.teamName = TeamName;
  96.             this.creatorName = CreatorName;
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement