Advertisement
elena1234

SetsOfElements-interview questions

Jan 5th, 2021
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SetsOfElements
  6. {
  7.     static class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int firstSetLength = input[0];
  13.             int secondSetLength = input[1];
  14.             var firstSet = new HashSet<int>();
  15.             var secondSet = new HashSet<int>();
  16.             for (int i = 0; i < firstSetLength; i++)
  17.             {
  18.                 int number = int.Parse(Console.ReadLine());
  19.                 firstSet.Add(number);
  20.             }
  21.  
  22.             for (int i = 0; i < secondSetLength; i++)
  23.             {
  24.                 int number = int.Parse(Console.ReadLine());
  25.                 secondSet.Add(number);
  26.             }
  27.  
  28.             var intersection= firstSet.Intersect(secondSet);
  29.             Console.WriteLine(string.Join(" ", intersection));
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement