Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Tseam_Account
  6. {
  7.     public class Program
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             var tseamAccount = Console.ReadLine()
  12.                                .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  13.                                .ToList();
  14.  
  15.             var inputCommand = string.Empty;
  16.  
  17.             while ((inputCommand = Console.ReadLine()) != "Play!")
  18.             {
  19.                 var tokens = inputCommand
  20.                             .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  21.                             .ToList();
  22.                 var currentCommand = tokens[0];
  23.  
  24.                 switch (currentCommand)
  25.                 {
  26.                     case "Install":
  27.                         var gameToAdd = tokens[1];
  28.  
  29.                         if (!CheckCurrentGameInAccount(gameToAdd, tseamAccount))
  30.                         {
  31.                             tseamAccount.Add(gameToAdd);
  32.                         }
  33.                         break;
  34.                     case "Uninstall":
  35.  
  36.                         var gameToDelete = tokens[1];
  37.  
  38.                         if (CheckCurrentGameInAccount(gameToDelete, tseamAccount))
  39.                         {
  40.                             tseamAccount.Remove(gameToDelete);
  41.                         }
  42.                         break;
  43.                     case "Update":
  44.                         var gameToUpdate = tokens[1];
  45.  
  46.                         if (CheckCurrentGameInAccount(gameToUpdate, tseamAccount))
  47.                         {
  48.                             tseamAccount.Remove(gameToUpdate);
  49.                             tseamAccount.Add(gameToUpdate);
  50.                         }
  51.                         break;
  52.                     case "Expansion":
  53.                         var gameExp = tokens[1];
  54.                         var currentGame = tokens[1].Split('-').ToList();
  55.                         if (CheckCurrentGameInAccount(currentGame[0], tseamAccount))
  56.                         {
  57.                             int index = tseamAccount.FindIndex(g => g == currentGame[0]);
  58.  
  59.                             var firstPartOfList = tseamAccount.Take(index + 1).ToList();
  60.                             var secondPartOfList = tseamAccount.Skip(index + 1).ToList();
  61.                             firstPartOfList.Add(gameExp);
  62.  
  63.                             tseamAccount.Clear();
  64.                             tseamAccount.AddRange(firstPartOfList);
  65.                             tseamAccount.AddRange(secondPartOfList);
  66.                         }
  67.                         break;
  68.                 }
  69.             }
  70.  
  71.             Console.WriteLine(string.Join(" ", tseamAccount));
  72.         }
  73.  
  74.         private static bool CheckCurrentGameInAccount(string gameName, List<string> account)
  75.         {
  76.             var game = account.FirstOrDefault(g => g == gameName);
  77.  
  78.             if (game == null)
  79.             {
  80.                 return false;
  81.             }
  82.             else
  83.             {
  84.                 return true;
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement