Advertisement
bacco

Change List

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