Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ChangeableList
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = ReadInput();
- string command = ProcessCommands(numbers);
- PrintResultByCommand(numbers, command);
- }
- private static List<int> ReadInput()
- {
- return Console.ReadLine()
- .Split(' ')
- .Where(x => x != "")
- .Select(int.Parse)
- .ToList();
- }
- private static string ProcessCommands(List<int> numbers)
- {
- string command = Console.ReadLine();
- while (command != "Odd" && command != "Even")
- {
- //Delete 5
- //Insert 10 1
- string[] commandArgs = command.Split(' ').ToArray();
- if (commandArgs[0] == "Insert")
- {
- int insertNumber = int.Parse(commandArgs[1]);
- int insertPossition = int.Parse(commandArgs[2]);
- numbers.Insert(insertPossition, insertNumber);
- }
- else if (commandArgs[0] == "Delete")
- {
- int deleteValue = int.Parse(commandArgs[1]);
- //Removes first match element
- // numbers.Remove(deleteValue);
- numbers.RemoveAll(x => x == deleteValue);
- }
- command = Console.ReadLine();
- }
- return command;
- }
- private static void PrintResultByCommand(List<int> numbers, string command)
- {
- if (command == "Odd")
- {
- numbers.RemoveAll(x => x % 2 == 0);
- }
- else
- {
- numbers.RemoveAll(x => x % 2 != 0);
- }
- Console.WriteLine(string.Join(" ", numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement