Advertisement
Guest User

Untitled

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