Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03.EasterShopping
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> shops = Console.ReadLine().Split().ToList();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] command = Console.ReadLine().Split();
- string word = command[0];
- if (word == "Include")
- {
- string currentShop = command[1];
- shops.Add(currentShop);
- }
- else if (word == "Visit")
- {
- int numberOfShops = int.Parse(command[2]);
- if (numberOfShops > shops.Count)
- {
- continue;
- }
- if (command[1] == "first")
- {
- for (int j = 0; j < numberOfShops; j++)
- {
- shops.Remove(shops[0]);
- }
- }
- else if (command[1] == "last")
- {
- for (int h = 0; h < numberOfShops; h++)
- {
- shops.Remove(shops[shops.Count - 1]);
- }
- }
- }
- else if (word == "Prefer")
- {
- int index1 = int.Parse(command[1]);
- int index2 = int.Parse(command[2]);
- if (index1 >= 0 && index1 < shops.Count && index2 >= 0 && index2 < shops.Count)
- {
- string shopIndex1 = shops[index1];
- string shopIndex2 = shops[index2];
- shops.Remove(shopIndex1);
- shops.Insert(index2, shopIndex1);
- shops.Remove(shopIndex2);
- shops.Insert(index1, shopIndex2);
- }
- }
- else if (word == "Place")
- {
- string currentShop = command[1];
- int index = int.Parse(command[2]);
- if (index + 1 >= 0 && index + 1 < shops.Count)
- {
- shops.Insert(index + 1, currentShop);
- }
- }
- }
- Console.WriteLine("Shops left:");
- Console.WriteLine(string.Join(" ", shops));
- }
- }
- }
Add Comment
Please, Sign In to add comment