Advertisement
svetlyoek

Untitled

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