Advertisement
silvana1303

easter shopping

Jun 16th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Threading;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> shops = Console.ReadLine().Split().ToList();
  14.  
  15.             int count = int.Parse(Console.ReadLine());
  16.  
  17.             for (int i = 0; i < count; i++)
  18.             {
  19.                 string[] command = Console.ReadLine().Split().ToArray();
  20.  
  21.                 if (command[0] == "Include")
  22.                 {
  23.                     shops.Add(command[1]);
  24.                 }
  25.                 if (command[1] == "first")
  26.                 {
  27.                     int shopCount = int.Parse(command[2]);
  28.                    
  29.                     if (shops.Count >= shopCount)
  30.                     {
  31.                         shops.RemoveRange(0, shopCount);
  32.                     }
  33.                 }
  34.                 if (command[1] == "last")
  35.                 {
  36.                     int shopCount = int.Parse(command[2]);
  37.  
  38.                     if (shops.Count >= shopCount)
  39.                     {
  40.                         shops.Reverse();
  41.                         shops.RemoveRange(0, shopCount);
  42.                         shops.Reverse();
  43.                     }
  44.                 }
  45.                 if (command[0] == "Prefer")
  46.  
  47.                 {
  48.                     int firstShop = int.Parse(command[1]);
  49.                     int secondShop = int.Parse(command[2]);
  50.  
  51.                     if (firstShop >= 0 && firstShop < shops.Count && (secondShop >= 0 && secondShop < shops.Count))
  52.                     {
  53.                         string temp = shops[firstShop];
  54.                         shops[firstShop] = shops[secondShop];
  55.                         shops[secondShop] = temp;
  56.                     }
  57.                 }
  58.                 if (command[0] == "Place")
  59.                 {
  60.                     int index = int.Parse(command[2]) + 1;
  61.                     if (index >= 0 && index < shops.Count)
  62.                     {
  63.                         shops.Insert(index, command[1]);
  64.                     }
  65.                 }
  66.             }
  67.  
  68.             Console.WriteLine("Shops left:");
  69.             Console.WriteLine(string.Join(" ", shops));
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement