Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _0
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> shops = Console.ReadLine()
- .Split(' ')
- .ToList();
- int countCommands = int.Parse(Console.ReadLine());
- for (int i = 0; i < countCommands; i++)
- {
- string[] commands = Console.ReadLine().Split(' ').ToArray();
- string currentCommand = commands[0];
- if (currentCommand == "Include")
- {
- shops.Add(commands[1]);
- }
- else if (currentCommand == "Visit")
- {
- string firstOrLast = commands[1];
- int numberShops = int.Parse(commands[2]);
- if (0 <= numberShops && shops.Count <= numberShops)
- {
- continue;
- }
- else if (firstOrLast == "first")
- {
- for (int j = 0; j < numberShops; j++)
- {
- shops.RemoveAt(0);
- }
- }
- else if (firstOrLast == "last")
- {
- for (int k = 0; k < numberShops; k++)
- {
- shops.RemoveAt(shops.Count - 1);
- }
- }
- }
- else if (currentCommand == "Prefer")
- {
- int shopIndexOne = int.Parse(commands[1]);
- int shopIndexTwo = int.Parse(commands[2]);
- if ((0 <= shopIndexOne && shopIndexOne < shops.Count) &&
- (0 <= shopIndexTwo && shopIndexTwo < shops.Count))
- {
- string firstShop = shops[shopIndexOne];
- string secondShop = shops[shopIndexTwo];
- shops.RemoveAt(shopIndexOne);
- shops.Insert(shopIndexOne, secondShop);
- shops.RemoveAt(shopIndexTwo);
- shops.Insert(shopIndexTwo, firstShop);
- }
- }
- else if (currentCommand == "Place")
- {
- string shop = commands[1];
- int shopIndex = int.Parse(commands[2]) + 1;
- if (0 <= shopIndex && shopIndex < shops.Count)
- {
- shops.Insert(shopIndex, shop);
- }
- }
- }
- Console.WriteLine("Shops left:");
- Console.WriteLine(string.Join(' ', shops));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment