Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ListOperations
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> lists = Console.ReadLine().Split().Select(int.Parse).ToList();
- string[] command = Console.ReadLine().ToLower().Split().ToArray();
- while (command[0] != "end")
- {
- if (command[0] == "add")
- {
- lists.Add(int.Parse(command[1]));
- }
- else if (command[0] == "insert")
- {
- if (int.Parse(command[2]) < 0 || int.Parse(command[2]) > lists.Count - 1)
- {
- Console.WriteLine("Invalid index");
- }
- else
- {
- lists.Insert(int.Parse(command[2]), int.Parse(command[1]));
- }
- }
- else if (command[0] == "remove")
- {
- if (int.Parse(command[1]) < 0 || int.Parse(command[1]) > lists.Count - 1)
- {
- Console.WriteLine("Invalid index");
- }
- else
- {
- lists.RemoveAt(int.Parse(command[1]));
- }
- }
- else if (command[0] == "shift" && command[1] == "left")
- {
- for (int i = 0; i < int.Parse(command[2]); i++)
- {
- lists.Add(lists[0]);
- lists.RemoveAt(0);
- }
- }
- else if (command[0] == "shift" && command[1] == "right")
- {
- for (int i = 0; i < int.Parse(command[2]); i++)
- {
- lists.Insert(0, lists[lists.Count - 1]);
- lists.RemoveAt(lists.Count - 1);
- }
- }
- command = Console.ReadLine().ToLower().Split().ToArray();
- }
- Console.WriteLine(string.Join(" ", lists));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement