Advertisement
gospod1978

List-Ex/Change List

Oct 19th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace fundamental14
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<int> originalList = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.            
  13.             string input = string.Empty;
  14.            
  15.             while((input = Console.ReadLine()) != "end")
  16.             {
  17.                 string[] arr = input.Split();
  18.                 string command = arr[0];
  19.                 int element = int.Parse(arr[1]);
  20.                
  21.                 if (command == "Delete")
  22.                 {
  23.                     originalList.RemoveAll(x => x == element);
  24.                
  25.                 }
  26.                 else
  27.                 {
  28.                     int index = int.Parse(arr[2]);
  29.                    
  30.                     originalList.Insert(index, element);
  31.                 }
  32.             }
  33.            
  34.             Console.WriteLine(string.Join(" ", originalList));
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement