Advertisement
YORDAN2347

FindEvenOrOdds

Feb 16th, 2021
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04._FindEvensOrOdds
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<long> input = Console.ReadLine()
  12.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(long.Parse)
  14.                 .ToList();
  15.             long down = input.Min();
  16.             long top = input.Max();
  17.  
  18.             string condition = Console.ReadLine();
  19.  
  20.             List<long> nums = new List<long>();
  21.             for (long i = down; i <= top; i++)
  22.             {
  23.                 nums.Add(i);
  24.             }
  25.  
  26.             Predicate<long> even = x => { return x % 2 == 0; };
  27.             Predicate<long> odd = x => { return x % 2 == 1; };
  28.  
  29.             if (condition == "even")
  30.             {
  31.                 Console.WriteLine(string.Join(" ", nums.FindAll(even)));
  32.             }
  33.             else
  34.             {
  35.                 Console.WriteLine(string.Join(" ", nums.FindAll(odd)));
  36.             }
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement