MiroslavKisov

CustomComparator

Feb 5th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace CustomComparator
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             var numbers = Console.ReadLine()
  12.                 .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.             Func<int, bool> comparatorEven = n => n % 2 == 0;
  16.             Func<int, bool> comparatorOdd = n => n % 2 != 0;
  17.             var evens = numbers.Where(comparatorEven).ToArray();
  18.             var odds = numbers.Where(comparatorOdd).ToArray();
  19.             Array.Sort(evens);
  20.             Array.Sort(odds);
  21.             Console.Write(string.Join(" ", evens) + " ");
  22.             Console.Write(string.Join(" ", odds));
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment