Advertisement
martinvalchev

Change_List

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