Advertisement
Vladimir76

Teamwork

Feb 10th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Teamwork_project
  8. {
  9.     class Team
  10.     {
  11.         public string Name { get; set; }
  12.         public string CreatorTeamName { get; set; }
  13.         public List<string> users { get; set; }
  14.     }
  15.  
  16.     class Program
  17.     {
  18.         static void Main()
  19.         {
  20.             int n = int.Parse(Console.ReadLine());
  21.             List<Team> teamList = new List<Team>();
  22.             List<string> messages = new List<string>();
  23.  
  24.             string[] inputArr;
  25.             string nameUser = null;
  26.             string input = null;
  27.             string nameTeam = null;
  28.             string messageStr = null;
  29.  
  30.             for (int i = 0; i < n; i++)
  31.             {
  32.                 input = Console.ReadLine();
  33.                 inputArr = input.Trim().Split('-');
  34.                 nameUser = inputArr[0];
  35.                 nameTeam = inputArr[1];
  36.                 if ((!teamList.Any(x => x.Name == nameTeam)) &&
  37.                     (!teamList.Any(x => x.CreatorTeamName == nameUser)))
  38.                 {
  39.                     Team team = new Team();
  40.                     team.users = new List<string>();
  41.                     team.CreatorTeamName = nameUser;
  42.                     team.Name = nameTeam;
  43.                     teamList.Add(team);
  44.                     messageStr = "Team " + nameTeam + " has been created by " + nameUser + "!";
  45.                     messages.Add(messageStr);
  46.                 }
  47.                 else
  48.                 {
  49.                     if (teamList.Any(x => x.Name == nameTeam))
  50.                     {
  51.                         messageStr = "Team " + nameTeam + " was already created!";
  52.                         messages.Add(messageStr);
  53.                     }
  54.                     if (teamList.Any(x => x.CreatorTeamName == nameUser))
  55.                     {
  56.                         messageStr = nameUser + " cannot create another team!";
  57.                         messages.Add(messageStr);
  58.                     }
  59.                 }
  60.             }
  61.      
  62.             do
  63.             {
  64.                 input = Console.ReadLine();
  65.                 if (input== "end of assignment")
  66.                 {
  67.                     break;
  68.                 }
  69.                 inputArr = input
  70.                     .Trim()
  71.                     .Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  72.                 nameUser = inputArr[0];
  73.                 nameTeam = inputArr[1];
  74.                 if (!teamList.Any(x => x.Name == nameTeam))
  75.                 {
  76.                     messageStr = "Team " + nameTeam + " does not exist!";
  77.                     messages.Add(messageStr);
  78.                 }
  79.                 else
  80.                 {
  81.                     if ((teamList.Any(x => x.users.Contains(nameUser))) ||
  82.                         (teamList.Any(x => x.CreatorTeamName == nameUser)))
  83.                     {
  84.                         messageStr = "Member " + nameUser + " cannot join team " + nameTeam + "!";
  85.                         messages.Add(messageStr);
  86.                     }
  87.                     else
  88.                     {
  89.                         int index = teamList.FindIndex(x => x.Name == nameTeam);
  90.                         teamList[index].users.Add(nameUser);
  91.                     }
  92.                 }
  93.                
  94.  
  95.             } while (input != "end of assignment");
  96.  
  97.             foreach (var message in messages)
  98.             {
  99.                 Console.WriteLine(message);
  100.             }
  101.             var sortTeamList = teamList.OrderByDescending(x => x.users.Count).OrderBy(x => x.Name);
  102.             List<string> disbandList = new List<string>();
  103.             foreach (var team in sortTeamList)
  104.             {
  105.                 if (team.users.Count > 0)
  106.                 {
  107.                     Console.WriteLine(team.Name);
  108.                     Console.WriteLine("- {0}", team.CreatorTeamName);
  109.                     var sortUsersName = team.users.OrderBy(x => x).ToList();
  110.                     for (int i = 0; i < sortUsersName.Count; i++)
  111.                     {
  112.                         Console.WriteLine("-- {0}",sortUsersName[i]);
  113.                     }
  114.                 }
  115.                 else
  116.                 {
  117.                     disbandList.Add(team.Name);
  118.                 }
  119.             }
  120.             Console.WriteLine("Teams to disband:");
  121.             if (disbandList.Count > 0)
  122.             {
  123.                 var sortDisbandList = disbandList.OrderBy(x => x);
  124.                 foreach (var sdl in sortDisbandList)
  125.                 {
  126.                     Console.WriteLine(sdl);
  127.                 }
  128.             }
  129.            
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement