Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int countCommands = int.Parse(Console.ReadLine());
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- int position = 0;
- for (int i = 0; i < countCommands; i++)
- {
- string line = Console.ReadLine();
- string[] lineParts = line.Split();
- string command = lineParts[0];
- if (command == "Forward")
- {
- int stepsForward = int.Parse(lineParts[1]);
- position += stepsForward;
- if (position >= 0 && position < numbers.Count)
- {
- numbers.RemoveAt(position);
- }
- else
- {
- position -= stepsForward;
- }
- }
- else if (command == "Back")
- {
- int stepsBack = int.Parse(lineParts[1]);
- position -= stepsBack;
- if (position >= 0 && position < numbers.Count)
- {
- numbers.RemoveAt(position);
- }
- else
- {
- position -= stepsBack;
- }
- }
- else if (command == "Gift")
- {
- int index = int.Parse(lineParts[1]);
- if (index >= 0 && index < numbers.Count)
- {
- int numberToInsert = int.Parse(lineParts[2]);
- numbers.Insert(index, numberToInsert);
- position = index;
- }
- }
- else if (command == "Swap")
- {
- int firstNum = int.Parse(lineParts[1]);
- int secondNum = int.Parse(lineParts[2]);
- if (numbers.Contains(firstNum) && numbers.Contains(secondNum))
- {
- int indexFirstNum = numbers.IndexOf(firstNum);
- int indexSecondNum = numbers.IndexOf(secondNum);
- numbers[indexFirstNum] = secondNum;
- numbers[indexSecondNum] = firstNum;
- }
- }
- }
- Console.WriteLine($"Position: {position}");
- Console.WriteLine(string.Join(", ", numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement