Advertisement
Guest User

Untitled

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