Advertisement
silvana1303

list operations

Jun 3rd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5. using System.Text;
  6.  
  7. namespace exampreparation
  8. {
  9.     class exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> list = Console.ReadLine().Split().ToList();
  14.  
  15.             List<string> input = Console.ReadLine().Split().ToList();
  16.  
  17.             while (input[0] != "End")
  18.             {
  19.                 if (input.Count == 2)
  20.                 {
  21.                     if (input[0] == "Add")
  22.                     {
  23.                         list.Add(input[1]);
  24.                     }
  25.                     else
  26.                     {
  27.                         int indexRemove = int.Parse(input[1]);
  28.  
  29.                         if (indexRemove >= list.Count || indexRemove < 0)
  30.                         {
  31.                             Console.WriteLine("Invalid index");
  32.                         }
  33.                         else
  34.                         {
  35.                             list.RemoveAt(indexRemove);
  36.                         }
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     if (input[0] == "Insert")
  42.                     {
  43.                         int indexInsert = int.Parse(input[2]);
  44.                  
  45.                         if (indexInsert >= list.Count || indexInsert < 0)
  46.                         {
  47.                             Console.WriteLine("Invalid index");
  48.                         }
  49.                         else
  50.                         {
  51.                             list.Insert(indexInsert, input[1]);
  52.                         }
  53.                     }
  54.                     else if (input[1] == "left")
  55.                     {
  56.                         int times = int.Parse(input[2]);
  57.  
  58.                         for (int i = 0; i < times; i++)
  59.                         {
  60.                             string temp = list[0];
  61.                             list.Remove(list[0]);
  62.                             list.Add(temp);
  63.                         }
  64.                     }
  65.                     else
  66.                     {
  67.                         int times = int.Parse(input[2]);
  68.  
  69.                         list.Reverse();
  70.  
  71.                         for (int i = 0; i < times; i++)
  72.                         {
  73.                             string temp = list[0];
  74.                             list.Remove(list[0]);
  75.                             list.Add(temp);
  76.                         }
  77.  
  78.                         list.Reverse();
  79.                     }
  80.                 }
  81.  
  82.                 input = Console.ReadLine().Split().ToList();
  83.             }
  84.  
  85.             Console.WriteLine(string.Join(" ", list));
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement