Advertisement
pifka

Sets of Elements

May 19th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Numerics;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9.  
  10. namespace solutions
  11. {
  12. class Program
  13. {
  14. public static void Main()
  15. {
  16. var sets = Console.ReadLine().Split().Select(int.Parse).ToArray();
  17.  
  18. var firstSet = new HashSet<string>();
  19. var secondSet = new HashSet<string>();
  20. var result = new HashSet<string>();
  21.  
  22. for (int i = 0; i < sets[0] + sets[1]; i++)
  23. {
  24. var input = Console.ReadLine();
  25.  
  26. if (i < sets[0])
  27. {
  28.  
  29. firstSet.Add(input);
  30. }
  31. else
  32. {
  33. secondSet.Add(input);
  34. }
  35. }
  36.  
  37. var minHash = new HashSet<string>();
  38. var maxHash = new HashSet<string>();
  39.  
  40. if (firstSet.Count < secondSet.Count)
  41. {
  42. minHash = firstSet;
  43. maxHash = secondSet;
  44. }
  45. else
  46. {
  47. minHash = secondSet;
  48. maxHash = firstSet;
  49. }
  50. foreach (var item in minHash)
  51. {
  52. if (maxHash.Contains(item))
  53. {
  54. result.Add(item);
  55. }
  56. }
  57.  
  58. Console.WriteLine(string.Join(" ", result));
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement