Advertisement
angelneychev

Untitled

Apr 16th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Easter_Shopping
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> shopsAll = Console.ReadLine().Split().ToList();
  12.             int number = int.Parse(Console.ReadLine());
  13.  
  14.             for (int i = 0; i < number; i++)
  15.             {
  16.                 string[] tokkens = Console.ReadLine().Split();
  17.  
  18.                 string command = tokkens[0];
  19.                 if (command == "Include")
  20.                 {
  21.                     string shop = tokkens[1];
  22.                     shopsAll.Add(shop);
  23.                 }
  24.                 else if (command == "Visit")
  25.                 {
  26.                     string countShop = tokkens[1];
  27.                     int countShop2 = int.Parse(tokkens[2]);
  28.                     if (countShop2 <= shopsAll.Count)
  29.                     {
  30.                         if (countShop == "first")
  31.                         {
  32.                             shopsAll.RemoveRange(0, countShop2);
  33.                         }
  34.                         else if (countShop == "last")
  35.                         {
  36.                             shopsAll.RemoveAt(shopsAll.Count - 1);
  37.                         }
  38.                     }
  39.                 }
  40.                 else if (command == "Prefer")
  41.                 {
  42.                     int shopIndex1 = int.Parse(tokkens[1]);
  43.                     int shopIndex2 = int.Parse(tokkens[2]);
  44.  
  45.                     if ((shopIndex1 > -1 && shopIndex1 < shopsAll.Count) &&
  46.                         (shopIndex2 > -1 && shopIndex2 < shopsAll.Count))
  47.                     {
  48.                         string word1 = shopsAll[shopIndex1];
  49.                         string word2 = shopsAll[shopIndex2];
  50.  
  51.                         shopsAll[shopIndex1] = word2;
  52.                         shopsAll[shopIndex2] = word1;
  53.                     }
  54.                     //ThriftShop ToyStore Groceries Armani PeakStore
  55.                 }
  56.                 else if (command == "Place")
  57.                 {
  58.                     string shop = tokkens[1];
  59.                     int index = int.Parse(tokkens[2]);
  60.                     if (index >-1 && index < shopsAll.Count-1)
  61.                     {
  62.                         shopsAll.Insert(index+1,shop);
  63.                     }
  64.                 }
  65.             }
  66.  
  67.             Console.WriteLine("Shops left:");
  68.             Console.WriteLine(string.Join(" ",shopsAll));
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement