Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _4.List_Operations
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- while (true)
- {
- string cmmnd = Console.ReadLine();
- if (cmmnd=="End")
- {
- break;
- }
- string[] command=cmmnd.Split();
- if (command[0]=="Add")
- {
- numbers.Add(int.Parse(command[1]));
- }
- else if (command[0]=="Insert")
- {
- if (int.Parse(command[1])<0||int.Parse(command[1])>=numbers.Count)
- {
- Console.WriteLine("Invalid index");
- }
- else
- {
- numbers.Insert(int.Parse(command[2]),int.Parse(command[1]));
- }
- }
- else if (command[0]=="Remove")
- {
- if (int.Parse(command[1])<0||int.Parse(command[1])>=numbers.Count)
- {
- Console.WriteLine("Invalid index");
- }
- else
- {
- numbers.RemoveAt(int.Parse(command[1]));
- }
- }
- else if(command[0]=="Shift"&&command[1]=="right")
- {
- for (int i=0;i<int.Parse(command[2]);i++)
- {
- numbers.Add(numbers[0]);
- numbers.RemoveAt(0);
- }
- }
- else if (command[0] == "Shift" && command[1] == "left")
- {
- for (int i = 0; i < int.Parse(command[2]); i++)
- {
- numbers.Insert(0, numbers[numbers.Count - 1]);
- numbers.RemoveAt(numbers.Count - 1);
- }
- }
- }
- Console.WriteLine(string.Join(" ", numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement