Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 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> numbers = Console.ReadLine()
  12.                                         .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13.                                         .Select(int.Parse)
  14.                                         .ToList();
  15.  
  16.             List<string> command = Console.ReadLine()
  17.                                           .ToLower()
  18.                                           .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  19.                                           .ToList();
  20.  
  21.             for (int i = 1; i < 3; i++)
  22.             {
  23.  
  24.                 if (command[0] == "delete")
  25.                 {
  26.                     int element = int.Parse(command[1]);
  27.  
  28.                     for (int j = 0; j < numbers.Count(); j++)
  29.                     {
  30.                         if (numbers[j] == element)
  31.                         {
  32.                             numbers.Remove(numbers[j]);
  33.                             j--;
  34.                         }
  35.                     }
  36.  
  37.                     i = 1;
  38.                 }
  39.                 else if (command[0] == "insert")
  40.                 {
  41.                     int element = int.Parse(command[1]);
  42.                     int index = int.Parse(command[2]);
  43.                     numbers.Insert(index, element);
  44.                     i = 1;
  45.                 }
  46.  
  47.                 if (command[0] == "odd" || command[0] == "even")
  48.                 {
  49.                     break;
  50.                 }
  51.  
  52.                 command = Console.ReadLine()
  53.                                          .ToLower()
  54.                                          .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  55.                                          .ToList();
  56.             }
  57.  
  58.             if (command[0] == "odd")
  59.             {
  60.                 for (int i = 0; i < numbers.Count; i++)
  61.                 {
  62.                     if (numbers[i] % 2 != 0)
  63.                     {
  64.                         Console.Write($"{numbers[i]} ");
  65.                     }
  66.                 }
  67.             }
  68.             else if (command[0] == "even")
  69.             {
  70.                 for (int i = 0; i < numbers.Count; i++)
  71.                 {
  72.                     if (numbers[i] % 2 == 0)
  73.                     {
  74.                         Console.Write($"{numbers[i]} ");
  75.                     }
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement