Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02._Sets_of_Elements
- {
- class SetsofElements
- {
- static void Main(string[] args)
- {
- var setsParameters = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- var setOne = new HashSet<int>();
- var setTwo = new HashSet<int>();
- if (setsParameters[0] > 0 && setsParameters[1] > 0)
- {
- for (int firsSet = 0; firsSet < setsParameters[0]; firsSet++)
- {
- setOne.Add(int.Parse(Console.ReadLine()));
- }
- for (int secondSet = 0; secondSet < setsParameters[1]; secondSet++)
- {
- setTwo.Add(int.Parse(Console.ReadLine()));
- }
- var duplicates = new HashSet<int>();
- for (int i = 0; i < setOne.Count; i++)
- {
- var temp = setOne.ElementAt(i);
- if (setTwo.Contains(temp))
- {
- duplicates.Add(temp);
- }
- }
- //var dupli = setOne.Intersect(setTwo);
- foreach (int item in duplicates)
- {
- Console.Write($"{item} ");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement