Advertisement
EmoRz

Problem 2. Sets of Elements

Sep 29th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SetOfElements
  6. {
  7.     class Start
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] arr = Console.ReadLine().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  12.             var first = arr[0];
  13.             var second = arr[1];
  14.             //
  15.             List<int> f = new List<int>();
  16.             List<int> s = new List<int>();
  17.             //
  18.             for (int i = 0; i < first; i++)
  19.             {
  20.                 int temp = int.Parse(Console.ReadLine());
  21.                 f.Add(temp);
  22.             }
  23.             for (int i = 0; i < second; i++)
  24.             {
  25.                 int temp = int.Parse(Console.ReadLine());
  26.                 s.Add(temp);
  27.             }
  28.             var equalElents = s.Where(a => f.Any(a1 => a1 == a)).ToList();
  29.    
  30.             Console.WriteLine(string.Join(" ", equalElents));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement