Advertisement
nikolayneykov

Untitled

Apr 16th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         List<string> list = new List<string>(Console.ReadLine().Split(" "));
  9.         int n = int.Parse(Console.ReadLine());
  10.  
  11.         for (int i = 0; i < n; i++)
  12.         {
  13.             string[] tokens = Console.ReadLine().Split(" ");
  14.             string command = tokens[0];
  15.  
  16.             if (command == "Include")
  17.             {
  18.                 string shop = tokens[1];
  19.                 list.Add(shop);
  20.             }
  21.             else if (command == "Visit")
  22.             {
  23.                 int count = int.Parse(tokens[2]);
  24.  
  25.                 if (list.Count > count)
  26.                 {
  27.                     if (tokens[1] == "first")
  28.                     {
  29.                         list.RemoveRange(0, count);
  30.                     }
  31.                     else if (tokens[1] == "last")
  32.                     {
  33.                         list.RemoveRange(list.Count - count, count);
  34.                     }
  35.                 }
  36.             }
  37.             else if (command == "Prefer")
  38.             {
  39.                 int index1 = int.Parse(tokens[1]);
  40.                 int index2 = int.Parse(tokens[2]);
  41.  
  42.                 if (index1 >= 0 && index1 < list.Count && index2 >= 0 && index2 < list.Count)
  43.                 {
  44.                     string temp = list[index1];
  45.                     list[index1] = list[index2];
  46.                     list[index2] = temp;
  47.                 }
  48.             }
  49.             else if (command == "Place")
  50.             {
  51.                 string shop = tokens[1];
  52.                 int index = int.Parse(tokens[2]);
  53.  
  54.                 if (index >= 0 && index < list.Count)
  55.                 {
  56.                     list.Insert(index + 1, shop);
  57.                 }
  58.             }
  59.         }
  60.  
  61.         Console.WriteLine($"Shops left:");
  62.         Console.WriteLine(string.Join(" ", list));
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement