Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ChangeList
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToList();
- List<string> command = Console.ReadLine()
- .ToLower()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- for (int i = 1; i < 3; i++)
- {
- if (command[0] == "delete")
- {
- int element = int.Parse(command[1]);
- for (int j = 0; j < numbers.Count(); j++)
- {
- if (numbers[j] == element)
- {
- numbers.Remove(numbers[j]);
- j--;
- }
- }
- i = 1;
- }
- else if (command[0] == "insert")
- {
- int element = int.Parse(command[1]);
- int index = int.Parse(command[2]);
- numbers.Insert(index, element);
- i = 1;
- }
- if (command[0] == "odd" || command[0] == "even")
- {
- break;
- }
- command = Console.ReadLine()
- .ToLower()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- }
- if (command[0] == "odd")
- {
- for (int i = 0; i < numbers.Count; i++)
- {
- if (numbers[i] % 2 != 0)
- {
- Console.Write($"{numbers[i]} ");
- }
- }
- }
- else if (command[0] == "even")
- {
- for (int i = 0; i < numbers.Count; i++)
- {
- if (numbers[i] % 2 == 0)
- {
- Console.Write($"{numbers[i]} ");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement