Teo_Yanchev

C# Fundamentals 16.04.2019 Mid Exam - Easter Shopping

Oct 1st, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _0
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> shops = Console.ReadLine()
  12. .Split(' ')
  13. .ToList();
  14.  
  15. int countCommands = int.Parse(Console.ReadLine());
  16. for (int i = 0; i < countCommands; i++)
  17. {
  18. string[] commands = Console.ReadLine().Split(' ').ToArray();
  19. string currentCommand = commands[0];
  20.  
  21. if (currentCommand == "Include")
  22. {
  23. shops.Add(commands[1]);
  24. }
  25. else if (currentCommand == "Visit")
  26. {
  27. string firstOrLast = commands[1];
  28. int numberShops = int.Parse(commands[2]);
  29. if (0 <= numberShops && shops.Count <= numberShops)
  30. {
  31. continue;
  32. }
  33. else if (firstOrLast == "first")
  34. {
  35. for (int j = 0; j < numberShops; j++)
  36. {
  37. shops.RemoveAt(0);
  38. }
  39. }
  40. else if (firstOrLast == "last")
  41. {
  42. for (int k = 0; k < numberShops; k++)
  43. {
  44. shops.RemoveAt(shops.Count - 1);
  45. }
  46. }
  47. }
  48. else if (currentCommand == "Prefer")
  49. {
  50. int shopIndexOne = int.Parse(commands[1]);
  51. int shopIndexTwo = int.Parse(commands[2]);
  52.  
  53. if ((0 <= shopIndexOne && shopIndexOne < shops.Count) &&
  54. (0 <= shopIndexTwo && shopIndexTwo < shops.Count))
  55. {
  56. string firstShop = shops[shopIndexOne];
  57. string secondShop = shops[shopIndexTwo];
  58.  
  59. shops.RemoveAt(shopIndexOne);
  60. shops.Insert(shopIndexOne, secondShop);
  61. shops.RemoveAt(shopIndexTwo);
  62. shops.Insert(shopIndexTwo, firstShop);
  63. }
  64. }
  65. else if (currentCommand == "Place")
  66. {
  67. string shop = commands[1];
  68. int shopIndex = int.Parse(commands[2]) + 1;
  69.  
  70. if (0 <= shopIndex && shopIndex < shops.Count)
  71. {
  72. shops.Insert(shopIndex, shop);
  73. }
  74. }
  75. }
  76.  
  77. Console.WriteLine("Shops left:");
  78. Console.WriteLine(string.Join(' ', shops));
  79. }
  80. }
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment