ralichka

Exam-16.04.2019-03.EasterShopping

Oct 31st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.EasterShopping
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> shops = Console.ReadLine().Split().ToList();
  12.             int n = int.Parse(Console.ReadLine());
  13.  
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 string[] command = Console.ReadLine().Split();
  17.                 string word = command[0];
  18.                 if (word == "Include")
  19.                 {
  20.                     string currentShop = command[1];
  21.                     shops.Add(currentShop);
  22.                 }
  23.                 else if (word == "Visit")
  24.                 {
  25.                     int numberOfShops = int.Parse(command[2]);
  26.                     if (numberOfShops > shops.Count)
  27.                     {
  28.                         continue;
  29.                     }
  30.                     if (command[1] == "first")
  31.                     {
  32.                         for (int j = 0; j < numberOfShops; j++)
  33.                         {
  34.                             shops.Remove(shops[0]);
  35.                         }
  36.                     }
  37.                     else if (command[1] == "last")
  38.                     {
  39.                         for (int h = 0; h < numberOfShops; h++)
  40.                         {
  41.                             shops.Remove(shops[shops.Count - 1]);
  42.                         }
  43.                     }
  44.                 }
  45.                 else if (word == "Prefer")
  46.                 {
  47.                     int index1 = int.Parse(command[1]);
  48.                     int index2 = int.Parse(command[2]);
  49.  
  50.                     if (index1 >= 0 && index1 < shops.Count && index2 >= 0 && index2 < shops.Count)
  51.                     {
  52.                         string shopIndex1 = shops[index1];
  53.                         string shopIndex2 = shops[index2];
  54.                         shops.Remove(shopIndex1);
  55.                         shops.Insert(index2, shopIndex1);
  56.                         shops.Remove(shopIndex2);
  57.                         shops.Insert(index1, shopIndex2);
  58.                     }
  59.                 }
  60.                 else if (word == "Place")
  61.                 {
  62.                     string currentShop = command[1];
  63.                     int index = int.Parse(command[2]);
  64.                     if (index + 1 >= 0 && index + 1 < shops.Count)
  65.                     {
  66.                         shops.Insert(index + 1, currentShop);
  67.                     }
  68.                 }
  69.  
  70.             }
  71.             Console.WriteLine("Shops left:");
  72.             Console.WriteLine(string.Join(" ", shops));
  73.  
  74.         }
  75.     }
  76. }
Add Comment
Please, Sign In to add comment