gabi11

Sets & Dictionaries Advanced - 02. Sets of Elements

May 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 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. using System.Text.RegularExpressions;
  7.  
  8. namespace Advanced
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var firstSet = new HashSet<string>();
  15.             var secondSet = new HashSet<string>();
  16.  
  17.             var setsSize = Console.ReadLine()
  18.                 .Split()
  19.                 .Select(int.Parse)
  20.                 .ToArray();
  21.  
  22.             for (int i = 0; i < setsSize.Sum(); i++)
  23.             {
  24.                 var element = Console.ReadLine();
  25.  
  26.                 if (i < setsSize[0])
  27.                 {
  28.                     firstSet.Add(element);
  29.                 }
  30.  
  31.                 else
  32.                 {
  33.                     secondSet.Add(element);
  34.                 }
  35.             }
  36.  
  37.             Console.WriteLine(string.Join(" ", firstSet.Where(x => secondSet.Contains(x))));
  38.         }
  39.     }
  40. }
Add Comment
Please, Sign In to add comment