Advertisement
ElviraPetkova

09. List Of Predicates 100/100

Oct 10th, 2019
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01._Basic_Stack_Operations__
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             int[] delimeters = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.  
  14.             Func<int, int, bool> isDivisible = (x, y) => x % y == 0;
  15.             List<int> numbers = new List<int>();
  16.  
  17.             for (int i = 1; i <= n; i++)
  18.             {
  19.                 bool isDiv = true;
  20.                 foreach (var delimiter in delimeters)
  21.                 {
  22.                     if(!isDivisible(i, delimiter))
  23.                     {
  24.                         isDiv = false;
  25.                         break;
  26.                     }
  27.                 }
  28.                 if (isDiv)
  29.                 {
  30.                     numbers.Add(i);
  31.                 }
  32.                
  33.             }
  34.            
  35.             Console.WriteLine(string.Join(" ",numbers));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement