Advertisement
Guest User

Untitled

a guest
Nov 4th, 2019
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _4.List_Operations
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.  
  15.             while (true)
  16.             {
  17.                 string cmmnd = Console.ReadLine();
  18.                 if (cmmnd=="End")
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 string[] command=cmmnd.Split();
  24.  
  25.                 if (command[0]=="Add")
  26.                 {
  27.                     numbers.Add(int.Parse(command[1]));
  28.                 }
  29.                 else if (command[0]=="Insert")
  30.                 {
  31.                     if (int.Parse(command[1])<0||int.Parse(command[1])>=numbers.Count)
  32.                     {
  33.                         Console.WriteLine("Invalid index");
  34.                     }
  35.                     else
  36.                     {
  37.                         numbers.Insert(int.Parse(command[2]),int.Parse(command[1]));
  38.                     }
  39.                 }
  40.                 else if (command[0]=="Remove")
  41.                 {
  42.                     if (int.Parse(command[1])<0||int.Parse(command[1])>=numbers.Count)
  43.                     {
  44.                         Console.WriteLine("Invalid index");
  45.                     }
  46.                     else
  47.                     {
  48.                         numbers.RemoveAt(int.Parse(command[1]));
  49.                     }
  50.                 }
  51.                 else if(command[0]=="Shift"&&command[1]=="right")
  52.                 {
  53.                     for (int i=0;i<int.Parse(command[2]);i++)
  54.                     {
  55.                         numbers.Add(numbers[0]);
  56.                         numbers.RemoveAt(0);
  57.                     }
  58.                 }
  59.                 else if (command[0] == "Shift" && command[1] == "left")
  60.                 {
  61.                     for (int i = 0; i < int.Parse(command[2]); i++)
  62.                     {
  63.                         numbers.Insert(0, numbers[numbers.Count - 1]);
  64.                         numbers.RemoveAt(numbers.Count - 1);
  65.                     }
  66.                 }
  67.             }
  68.             Console.WriteLine(string.Join(" ", numbers));
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement