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
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- while (true)
- {
- List<string> command = Console.ReadLine().Split().ToList();
- if (command.Contains("End"))
- {
- Console.WriteLine(string.Join(" ", numbers));
- return;
- }
- else if (command.Contains("Add"))
- {
- numbers.Add(int.Parse(command[1]));
- }
- else if (command.Contains("Insert"))
- {
- int index = int.Parse(command[2]);
- if (index<numbers.Count)
- {
- int number = int.Parse(command[1]);
- numbers.Insert(index, number);
- }
- else
- {
- Console.WriteLine("Invalid index");
- }
- }
- else if (command.Contains("Remove"))
- {
- int index = int.Parse(command[1]);
- if (index<numbers.Count)
- {
- numbers.RemoveAt(index);
- }
- else
- {
- Console.WriteLine("Invalid index");
- }
- }
- else if (command.Contains("left"))
- {
- int count = int.Parse(command[2]);
- for (int i = 1; i <= count; i++)
- {
- numbers.Add(numbers[0]);
- numbers.RemoveAt(0);
- }
- }
- else if (command.Contains("right"))
- {
- int count = int.Parse(command[2]);
- for (int i = 1; i <= count; i++)
- {
- numbers.Insert(0, numbers[numbers.Count - 1]);
- numbers.RemoveAt(numbers.Count - 1);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement