vstoyanov

Untitled

Oct 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.70 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 _08.Mentor_Group
  8. {
  9.     class Team
  10.  
  11.     {
  12.         public string nameTeam { get; set; }
  13.  
  14.         public List<string> people { get; set; }
  15.  
  16.         public string nameCreator { get; set; }
  17.  
  18.  
  19.     }
  20.     class Program
  21.     {
  22.         static void Main(string[] args)
  23.         {
  24.  
  25.             int count = int.Parse(Console.ReadLine());
  26.             Team firstPlayer = new Team();
  27.  
  28.             Dictionary<string, string> leadersAndTeams = new Dictionary<string, string>();
  29.  
  30.             Dictionary<string, List<string>> teamMates = new Dictionary<string, List<string>>();
  31.  
  32.  
  33.             for (int i = 0; i < count; i++)
  34.             {
  35.                 string[] inputTeams = Console.ReadLine().Split('-').ToArray();
  36.  
  37.  
  38.  
  39.                 string leader = inputTeams[0];
  40.                 string team = inputTeams[1];
  41.  
  42.                 if (leadersAndTeams.ContainsValue(team))
  43.                 {
  44.                     Console.WriteLine($"Team {team} was already created!");
  45.                 }
  46.                 if (leadersAndTeams.ContainsKey(leader))
  47.                 {
  48.                     Console.WriteLine($"{leader} cannot create another team!");
  49.                 }
  50.  
  51.                 if (!leadersAndTeams.ContainsKey(leader))
  52.                 {
  53.                     leadersAndTeams.Add(leader, team);
  54.  
  55.                     Console.WriteLine($"Team {team} has been created by {leader}!");
  56.  
  57.                 }
  58.  
  59.                 firstPlayer.nameCreator = leader;
  60.                 firstPlayer.nameTeam = team;
  61.  
  62.  
  63.  
  64.  
  65.             }
  66.  
  67.             firstPlayer.people = new List<string>();
  68.             //after input
  69.             string[] playersAndTeams = Console.ReadLine().Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  70.             while (playersAndTeams[0] != "end of assignment")
  71.             {
  72.                 string namePlayer = playersAndTeams[0];
  73.                 string teamToJoin = playersAndTeams[1];
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.                 if (leadersAndTeams.ContainsValue(teamToJoin))
  81.                 {
  82.                     firstPlayer.nameTeam = teamToJoin;
  83.  
  84.  
  85.                     firstPlayer.people.Add(namePlayer);
  86.  
  87.  
  88.  
  89.                     if (!teamMates.ContainsKey(teamToJoin))
  90.                     {
  91.                         teamMates.Add(teamToJoin, new List<string>());
  92.                         teamMates[teamToJoin].Add(namePlayer);
  93.                     }
  94.                     else
  95.                     {
  96.                         teamMates[teamToJoin].Add(namePlayer);
  97.                     }
  98.  
  99.  
  100.  
  101.                 }
  102.                 else
  103.                 {
  104.                     Console.WriteLine($"Team {teamToJoin} does not exist!");
  105.                 }
  106.  
  107.  
  108.                 playersAndTeams = Console.ReadLine().Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  109.             }
  110.  
  111.             // output
  112.  
  113.             foreach (var item in leadersAndTeams)
  114.             {
  115.                 Console.WriteLine(item.Value);
  116.                 Console.WriteLine($"- {item.Key}");
  117.  
  118.  
  119.                 foreach (var mates in teamMates)
  120.                 {
  121.                     if (mates.Value.Count > 0)
  122.                     {
  123.                         Console.WriteLine($"-- {string.Join(Environment.NewLine,mates.Value)}");
  124.                     }
  125.                 }
  126.  
  127.  
  128.  
  129.  
  130.             }
  131.  
  132.             foreach (var item in teamMates)
  133.             {
  134.                 if (item.Value.Count == 0)
  135.                 {
  136.                     Console.WriteLine("Teams to disband:");
  137.                     Console.WriteLine(item.Key);
  138.                 }
  139.  
  140.             }
  141.  
  142.         }
  143.  
  144.  
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment