Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace fundamental14
- {
- class MainClass
- {
- public static void Main()
- {
- List<int> originalList = Console.ReadLine().Split().Select(int.Parse).ToList();
- string input = string.Empty;
- while((input = Console.ReadLine()) != "End")
- {
- string[] arr = input.Split();
- string command = arr[0];
- int number = 0;
- int index = 0;
- if (command == "Add")
- {
- number = int.Parse(arr[1]);
- originalList.Add(number);
- }
- else if(command == "Insert")
- {
- number = int.Parse(arr[1]);
- index = int.Parse(arr[2]);
- if (index >= originalList.Count || index < 0)
- {
- Console.WriteLine("Invalid index");
- }
- else
- {
- originalList.Insert(index, number);
- }
- }
- else if (command == "Remove")
- {
- index = int.Parse(arr[1]);
- if (index >= originalList.Count || index < 0)
- {
- Console.WriteLine("Invalid index");
- }
- else
- {
- originalList.RemoveAt(index);
- }
- }
- else if (command == "Shift")
- {
- string direction = arr[1];
- int count = int.Parse(arr[2]);
- if (direction == "left")
- {
- for (int j = 0; j < count; j++)
- {
- int current = originalList[0];
- for (int i = 0; i < originalList.Count - 1; i++)
- {
- originalList[i] = originalList[i + 1];
- }
- originalList[originalList.Count - 1] = current;
- }
- }
- else
- {
- for (int j = 0; j < count; j++)
- {
- int current = originalList[originalList.Count - 1];
- for (int i = originalList.Count - 1; i > 0; i--)
- {
- originalList[i] = originalList[i - 1];
- }
- originalList[0] = current;
- }
- }
- }
- }
- Console.WriteLine(string.Join(" ", originalList));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment