aggressiveviking

Untitled

Jun 22nd, 2020
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Easter_Shopping
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> shopList = Console.ReadLine().Split().ToList();
  12.             int n = int.Parse(Console.ReadLine());
  13.  
  14.             for (int i = 1; i <= n; i++)
  15.             {
  16.                 string[] theCommand = Console.ReadLine().Split();
  17.  
  18.                 if (theCommand[0] == "Include")
  19.                 {
  20.                     // Include {shop}":
  21.                     // Add the shop at the end of your list.
  22.                     string newShop = theCommand[1];
  23.  
  24.                     shopList.Add(newShop);
  25.                 }
  26.                 else if (theCommand[0] == "Visit")
  27.                 {
  28.                     // Visit {first/last} {numberOfShops}"
  29.                     // Remove either the "first" or the "last" number of shops from your list,
  30.                     // depending on the input.
  31.                     // If you have less shops on your list than the given number, skip this command.
  32.                     int numberOfShops = int.Parse(theCommand[2]);
  33.  
  34.                     if (theCommand[1] == "first")
  35.                     {
  36.                         if (shopList.Count >= numberOfShops)
  37.                         {
  38.                             for (int j = 1; j <= numberOfShops; j++)
  39.                             {
  40.                                 shopList.RemoveAt(0);
  41.                             }
  42.                         }
  43.                     }
  44.                     else if (theCommand[1] == "last")
  45.                     {
  46.                         if (shopList.Count >= numberOfShops)
  47.                         {
  48.                             for (int j = 1; j <= numberOfShops; j++)
  49.                             {
  50.                                 shopList.RemoveAt(shopList.Count - 1);
  51.                             }
  52.                         }
  53.                     }
  54.                 }
  55.                 else if (theCommand[0] == "Prefer")
  56.                 {
  57.                     // Prefer {shopIndex1} {shopIndex2}":
  58.                     // If both of the shop indexes exist in your list,
  59.                     // take the shops that are on them and change their places.
  60.                     int shopIndex1 = int.Parse(theCommand[1]);
  61.                     int shopIndex2 = int.Parse(theCommand[2]);
  62.  
  63.                     bool index1Existing = shopIndex1 >= 0 && shopIndex1 <= shopList.Count - 1;
  64.                     bool index2Existing = shopIndex2 >= 0 && shopIndex2 <= shopList.Count - 1;
  65.  
  66.                     if (index1Existing && index2Existing)
  67.                     {
  68.                         string temp = shopList[shopIndex1];
  69.                         shopList[shopIndex1] = shopList[shopIndex2];
  70.                         shopList[shopIndex2] = temp;
  71.                     }
  72.                 }
  73.                 else if (theCommand[0] == "Place")
  74.                 {
  75.                     // Place {shop} {shopIndex}"
  76.                     // Insert the shop after the given index, only if the resulted index exists.
  77.                     string newShop = theCommand[1];
  78.                     int checkIndex = int.Parse(theCommand[2]);
  79.  
  80.                     if (checkIndex >= 0 && checkIndex <= shopList.Count - 2)
  81.                     {
  82.                         //if (checkIndex == shopList.Count-1)
  83.                         //{
  84.                         //    shopList.Add(newShop);
  85.                         //}
  86.                         //else
  87.                         //{
  88.                         //    shopList.Insert(checkIndex + 1, newShop);
  89.                         //}
  90.  
  91.                         shopList.Insert(checkIndex + 1, newShop);
  92.                     }
  93.                 }
  94.             }
  95.  
  96.             Console.WriteLine("Shops left:");
  97.             Console.WriteLine(string.Join(" ", shopList));
  98.  
  99.             //Console.WriteLine("Hello World!");
  100.         }
  101.     }
  102. }
Add Comment
Please, Sign In to add comment