Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ListOfOperations
- {
- class Program
- {
- public static void Main()
- {
- List<int> listOfIntegers =
- Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- while (true)
- {
- string lineInput = Console.ReadLine();
- if (lineInput == "End")
- {
- break;
- }
- string[] commandInput = lineInput.Split();
- switch (commandInput[0])
- {
- case "Add":
- listOfIntegers.Insert
- (listOfIntegers.Count,
- int.Parse(commandInput[1]));
- break;
- case "Insert":
- listOfIntegers.Insert(
- int.Parse(commandInput[2]),
- int.Parse(commandInput[1]));
- break;
- case "Remove":
- if (int.Parse(commandInput[1]) < 0 ||
- int.Parse(commandInput[1])>listOfIntegers.Count)
- {
- Console.WriteLine("Invalid index");
- }
- else
- {
- listOfIntegers.RemoveAt(int.Parse(commandInput[1]));
- }
- break;
- case "Shift":
- if (commandInput[1] == "left")
- {
- for (int i = 0; i < int.Parse(commandInput[2]); i++)
- {
- int firstIndexElement = listOfIntegers[0];
- listOfIntegers.RemoveAt(0);
- listOfIntegers.Insert
- (listOfIntegers.Count,
- firstIndexElement);
- }
- }
- if (commandInput[1] == "right")
- {
- for (int i = 0; i < int.Parse(commandInput[2]); i++)
- {
- int lastIndexElement = listOfIntegers[listOfIntegers.Count - 1];
- listOfIntegers.RemoveAt(listOfIntegers.Count - 1);
- listOfIntegers.Insert(0, lastIndexElement);
- }
- }
- break;
- default:
- break;
- }
- }
- string result = string.Join(" ", listOfIntegers);
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement