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 ArrayManipulator
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
- string[] command = Console.ReadLine().Split();
- while (!command[0].Equals("end"))
- {
- if (command[0].Equals("exchange"))
- {
- int exchangeIndex = int.Parse(command[1]);
- if (exchangeIndex < numbers.Length)
- {
- int count = int.Parse(command[1]);
- int[] first = (numbers.Skip(count + 1).Take(numbers.Length - (count + 1))).ToArray();
- int[] second = (numbers.Take(count + 1)).ToArray();
- var result = first.Union(second).ToArray();
- numbers = result;
- }
- else
- {
- Console.WriteLine("Invalid index");
- }
- }
- else if (command[0].Equals("max"))
- {
- if (command[1].Equals("even"))
- {
- if (numbers.Any(x => x % 2 == 0))
- {
- var maxEven = numbers.Where(x => x % 2 == 0).Max();
- Console.WriteLine(numbers.ToList().LastIndexOf(maxEven));
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- else
- {
- if (numbers.Any(x => x % 2 != 0))
- {
- var maxOdd = numbers.Where(x => x % 2 != 0).Max();
- Console.WriteLine(numbers.ToList().LastIndexOf(maxOdd));
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- }
- else if (command[0].Equals("min"))
- {
- if (command[1].Equals("even"))
- {
- if (numbers.Any(x => x % 2 == 0))
- {
- var minEven = numbers.Where(x => x % 2 == 0).Min();
- Console.WriteLine(numbers.ToList().LastIndexOf(minEven));
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- else
- {
- if (numbers.Any(x => x % 2 != 0))
- {
- var minOdd = numbers.Where(x => x % 2 != 0).Min();
- Console.WriteLine(numbers.ToList().LastIndexOf(minOdd));
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- }
- else if (command[0].Equals("first"))
- {
- int count = int.Parse(command[1]);
- if (count < numbers.Length)
- {
- if (command[2].Equals("even"))
- {
- if (numbers.Any(x => x % 2 == 0))
- {
- var firstEven = numbers.Where(x => x % 2 == 0).Take(count);
- Console.WriteLine("[{0}]", string.Join(", ", firstEven));
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- else
- {
- if (numbers.Any(x => x % 2 != 0))
- {
- var firstOdd = numbers.Where(x => x % 2 != 0).Take(count);
- Console.WriteLine("[{0}]", string.Join(", ", firstOdd));
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- }
- else
- {
- Console.WriteLine("Invalid count");
- }
- }
- else if (command[0].Equals("last"))
- {
- int count = int.Parse(command[1]);
- if (count <= numbers.Length)
- {
- if (command[2].Equals("even"))
- {
- var lastEven = numbers.Where(x => x % 2 == 0).Reverse().Take(count).Reverse();
- Console.WriteLine("[{0}]", string.Join(", ", lastEven));
- }
- else
- {
- var lastOdd = numbers.Where(x => x % 2 != 0).Reverse().Take(count).Reverse();
- Console.WriteLine("[{0}]", string.Join(", ", lastOdd));
- }
- }
- else
- {
- Console.WriteLine("Invalid count");
- }
- }
- command = Console.ReadLine().Split();
- }
- Console.WriteLine("[{0}]", string.Join(", ", numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement