Advertisement
Sabev

Volley Team

Feb 4th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Demo
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var team = Console.ReadLine().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  12.  
  13.             var input = string.Empty;
  14.             while ((input = Console.ReadLine()) != "STOP")
  15.             {
  16.                 var tokens = input.Split().ToList();
  17.                 var command = tokens[0];
  18.  
  19.                 if (command == "Add")
  20.                 {
  21.                     var player = tokens[1];
  22.                     if (!team.Contains(player))
  23.                     {
  24.                         team.Add(player);
  25.                         Console.WriteLine($"{player} has been added to the team.");
  26.                     }
  27.                     else
  28.                     {
  29.                         Console.WriteLine($"{player} is already part of the team.");
  30.                     }
  31.                 }
  32.                 else if (command == "Remove")
  33.                 {
  34.                     var player = tokens[1];
  35.                     if (!team.Contains(player))
  36.                     {
  37.  
  38.                         Console.WriteLine($"{player} is not part of the team.");
  39.  
  40.                     }
  41.                     else
  42.                     {
  43.                         team.Remove(player);
  44.                         Console.WriteLine($"{player} has been removed.");
  45.  
  46.                     }
  47.                 }
  48.                 else if (command == "Change")
  49.                 {
  50.                     List<string> players = tokens[1].Split('|').ToList();
  51.                     string firstPlayer = players[0];
  52.                     string secondPlayer = players[1];
  53.  
  54.                     if (team.Contains(firstPlayer))
  55.                     {
  56.                         //team.Select(p => p.Replace(firstPlayer, secondPlayer));
  57.                         team[team.FindIndex(i => i.Equals(firstPlayer))] = secondPlayer;
  58.                         Console.WriteLine($"Successfully changed {firstPlayer} with {secondPlayer}.");
  59.                     }
  60.                     else
  61.                     {
  62.                         Console.WriteLine($"{firstPlayer} is not part of the team.");
  63.                     }
  64.                 }
  65.  
  66.                 if (team.Count == 0)
  67.                 {
  68.                     Console.WriteLine("There are no players left in the team.");
  69.                     break;
  70.                 }
  71.             }
  72.             if (team.Count != 0)
  73.             {
  74.                 Console.WriteLine(string.Join(", ", team));
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement