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