Advertisement
Guest User

Untitled

a guest
Jun 21st, 2020
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5.  
  6. namespace exampreparation
  7. {
  8. class exam
  9. {
  10. static void Main(string[] args)
  11. {
  12.  
  13. int times = int.Parse(Console.ReadLine());
  14. List<string> numbers = Console.ReadLine().Split().ToList();
  15.  
  16. string[] command = Console.ReadLine().Split().ToArray();
  17.  
  18. int startIndex = 0;
  19. int endIndex = 0;
  20.  
  21. for (int i = 0; i < times; i++)
  22. {
  23. if (command[0] == "Forward")
  24. {
  25. int steps = int.Parse(command[1]);
  26. endIndex = startIndex + steps;
  27.  
  28. if (endIndex >= 0 && endIndex < numbers.Count)
  29. {
  30. numbers.RemoveAt(endIndex);
  31. }
  32. else
  33. {
  34. endIndex = startIndex - steps;
  35. }
  36.  
  37. }
  38. if (command[0] == "Back")
  39. {
  40. int steps = int.Parse(command[1]);
  41. endIndex = startIndex - steps;
  42.  
  43. if (endIndex >= 0 && endIndex < numbers.Count)
  44. {
  45. numbers.RemoveAt(endIndex);
  46. }
  47. else
  48. {
  49. endIndex = startIndex + steps;
  50. }
  51. }
  52. if (command[0] == "Gift")
  53. {
  54. int index = int.Parse(command[1]);
  55. string numb = command[2];
  56. if (index >= 0 && index < numbers.Count)
  57. {
  58. numbers.Insert(index, numb);
  59. endIndex = index;
  60. }
  61. }
  62. if (command[0] == "Swap")
  63. {
  64. int index1 = int.Parse(command[1]);
  65. int index2 = int.Parse(command[2]);
  66.  
  67. string temp = command[index1];
  68. command[index1] = command[index2];
  69. command[index2] = temp;
  70.  
  71. }
  72.  
  73. startIndex = endIndex;
  74.  
  75. }
  76.  
  77. Console.WriteLine($"Position {endIndex}");
  78. Console.WriteLine(string.Join(", ", numbers));
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement