Advertisement
gabi11

Functional Programming - 06. Reverse And Exclude

May 26th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7.  
  8. namespace CSharpAdvanced
  9. {
  10.  
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             var numbers = Console.ReadLine()
  16.                 .Split()
  17.                 .Select(int.Parse)
  18.                 .ToList();
  19.  
  20.             int n = int.Parse(Console.ReadLine());
  21.  
  22.             var finalNumbers = new List<int>();
  23.  
  24.             Predicate<int> divisibleBy = x => x % n != 0;
  25.        
  26.             for (int i = 0; i < numbers.Count; i++)
  27.             {
  28.                 if (divisibleBy(numbers[i]))
  29.                 {
  30.                     finalNumbers.Add(numbers[i]);
  31.                 }
  32.             }
  33.  
  34.             finalNumbers.Reverse();
  35.  
  36.             Console.WriteLine(string.Join(" ", finalNumbers));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement