kirililchev3

Change List

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