ElviraPetkova

Change List

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