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