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