Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03._Easter_Shopping
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> shopList = Console.ReadLine().Split().ToList();
- int n = int.Parse(Console.ReadLine());
- for (int i = 1; i <= n; i++)
- {
- string[] theCommand = Console.ReadLine().Split();
- if (theCommand[0] == "Include")
- {
- // Include {shop}":
- // Add the shop at the end of your list.
- string newShop = theCommand[1];
- shopList.Add(newShop);
- }
- else if (theCommand[0] == "Visit")
- {
- // Visit {first/last} {numberOfShops}"
- // Remove either the "first" or the "last" number of shops from your list,
- // depending on the input.
- // If you have less shops on your list than the given number, skip this command.
- int numberOfShops = int.Parse(theCommand[2]);
- if (theCommand[1] == "first")
- {
- if (shopList.Count >= numberOfShops)
- {
- for (int j = 1; j <= numberOfShops; j++)
- {
- shopList.RemoveAt(0);
- }
- }
- }
- else if (theCommand[1] == "last")
- {
- if (shopList.Count >= numberOfShops)
- {
- for (int j = 1; j <= numberOfShops; j++)
- {
- shopList.RemoveAt(shopList.Count - 1);
- }
- }
- }
- }
- else if (theCommand[0] == "Prefer")
- {
- // Prefer {shopIndex1} {shopIndex2}":
- // If both of the shop indexes exist in your list,
- // take the shops that are on them and change their places.
- int shopIndex1 = int.Parse(theCommand[1]);
- int shopIndex2 = int.Parse(theCommand[2]);
- bool index1Existing = shopIndex1 >= 0 && shopIndex1 <= shopList.Count - 1;
- bool index2Existing = shopIndex2 >= 0 && shopIndex2 <= shopList.Count - 1;
- if (index1Existing && index2Existing)
- {
- string temp = shopList[shopIndex1];
- shopList[shopIndex1] = shopList[shopIndex2];
- shopList[shopIndex2] = temp;
- }
- }
- else if (theCommand[0] == "Place")
- {
- // Place {shop} {shopIndex}"
- // Insert the shop after the given index, only if the resulted index exists.
- string newShop = theCommand[1];
- int checkIndex = int.Parse(theCommand[2]);
- if (checkIndex >= 0 && checkIndex <= shopList.Count - 2)
- {
- //if (checkIndex == shopList.Count-1)
- //{
- // shopList.Add(newShop);
- //}
- //else
- //{
- // shopList.Insert(checkIndex + 1, newShop);
- //}
- shopList.Insert(checkIndex + 1, newShop);
- }
- }
- }
- Console.WriteLine("Shops left:");
- Console.WriteLine(string.Join(" ", shopList));
- //Console.WriteLine("Hello World!");
- }
- }
- }
Add Comment
Please, Sign In to add comment