Advertisement
YavorGrancharov

Change_List

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