Advertisement
igrilkul

Teamwork Projects

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