Advertisement
Lazov

02. Sets of Elements

Jan 24th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Sets_of_Elements
  6. {
  7. class SetsofElements
  8. {
  9. static void Main(string[] args)
  10. {
  11. var setsParameters = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  12.  
  13. var setOne = new HashSet<int>();
  14. var setTwo = new HashSet<int>();
  15.  
  16. if (setsParameters[0] > 0 && setsParameters[1] > 0)
  17. {
  18. for (int firsSet = 0; firsSet < setsParameters[0]; firsSet++)
  19. {
  20. setOne.Add(int.Parse(Console.ReadLine()));
  21.  
  22. }
  23.  
  24. for (int secondSet = 0; secondSet < setsParameters[1]; secondSet++)
  25. {
  26. setTwo.Add(int.Parse(Console.ReadLine()));
  27.  
  28. }
  29.  
  30. var duplicates = new HashSet<int>();
  31.  
  32.  
  33.  
  34. for (int i = 0; i < setOne.Count; i++)
  35. {
  36. var temp = setOne.ElementAt(i);
  37. if (setTwo.Contains(temp))
  38. {
  39. duplicates.Add(temp);
  40. }
  41. }
  42.  
  43. //var dupli = setOne.Intersect(setTwo);
  44.  
  45. foreach (int item in duplicates)
  46. {
  47. Console.Write($"{item} ");
  48. }
  49.  
  50.  
  51. }
  52.  
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement