Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Numerics;
- namespace exampreparation
- {
- class exam
- {
- static void Main(string[] args)
- {
- int times = int.Parse(Console.ReadLine());
- List<string> numbers = Console.ReadLine().Split().ToList();
- string[] command = Console.ReadLine().Split().ToArray();
- int startIndex = 0;
- int endIndex = 0;
- for (int i = 0; i < times; i++)
- {
- if (command[0] == "Forward")
- {
- int steps = int.Parse(command[1]);
- endIndex = startIndex + steps;
- if (endIndex >= 0 && endIndex < numbers.Count)
- {
- numbers.RemoveAt(endIndex);
- }
- else
- {
- endIndex = startIndex - steps;
- }
- }
- if (command[0] == "Back")
- {
- int steps = int.Parse(command[1]);
- endIndex = startIndex - steps;
- if (endIndex >= 0 && endIndex < numbers.Count)
- {
- numbers.RemoveAt(endIndex);
- }
- else
- {
- endIndex = startIndex + steps;
- }
- }
- if (command[0] == "Gift")
- {
- int index = int.Parse(command[1]);
- string numb = command[2];
- if (index >= 0 && index < numbers.Count)
- {
- numbers.Insert(index, numb);
- endIndex = index;
- }
- }
- if (command[0] == "Swap")
- {
- int index1 = int.Parse(command[1]);
- int index2 = int.Parse(command[2]);
- string temp = command[index1];
- command[index1] = command[index2];
- command[index2] = temp;
- }
- startIndex = endIndex;
- }
- Console.WriteLine($"Position {endIndex}");
- Console.WriteLine(string.Join(", ", numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement