Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.ThirdExercise
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> games = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToList();
  12.             List<string> installedGames = new List<string>();
  13.  
  14.             foreach (var item in games)
  15.             {
  16.                 installedGames.Add(item);
  17.             }
  18.  
  19.             string command = Console.ReadLine();
  20.             while (command != "Play!")
  21.             {
  22.                 string[] tokens = command.Split(' ', StringSplitOptions.RemoveEmptyEntries);
  23.                 string commandName = tokens[0];
  24.                 string game = tokens[1];
  25.  
  26.                 if (commandName == "Install")
  27.                 {
  28.                     if (installedGames.Contains(game) == false)
  29.                     {
  30.                         games.Add(game);
  31.                         installedGames.Add(game);
  32.                     }
  33.                 }
  34.                 else if (commandName == "Uninstall")
  35.                 {
  36.                     if (games.Contains(game))
  37.                     {
  38.                         games.Remove(game);
  39.                     }
  40.                 }
  41.                 else if (commandName == "Update")
  42.                 {
  43.                     if (games.Contains(game))
  44.                     {
  45.                         games.Remove(game);
  46.                         games.Add(game);
  47.                     }
  48.  
  49.                 }
  50.                 else if (commandName == "Expansion")
  51.                 {
  52.                     string[] tok = game.Split('-');
  53.                     string gameName = tok[0];
  54.                     string expansion = tok[1];
  55.  
  56.                     if (games.Contains(gameName))
  57.                     {
  58.                         int index = games.IndexOf(gameName);
  59.                         string value = $"{gameName}:{expansion}";
  60.                         if (index == games.Count - 1)
  61.                         {
  62.                             games.Add(value);
  63.                         }
  64.                         else
  65.                         {
  66.                             games.Insert(index + 1, value);
  67.                         }
  68.                     }
  69.                 }
  70.                 command = Console.ReadLine();
  71.             }
  72.  
  73.             Console.WriteLine(string.Join(" ",games));
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement