petyaminkova91

Untitled

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