fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var list1 = new List<int>() { 1, 2, 3, 4 };
  10. var list2 = new List<int>() { 2, 3, 5, 6, 7, 8 };
  11. var list3 = new List<int>() { 3, 4, 5 };
  12. var all = new HashSet<int>(list1.Concat(list2).Concat(list3));
  13.  
  14. int?[] l1Result = new int?[all.Count];
  15. int?[] l2Result = new int?[all.Count];
  16. int?[] l3Result = new int?[all.Count];
  17.  
  18. int idx = 0;
  19. foreach (int val in all)
  20. {
  21. if (list1.BinarySearch(val) >= 0) l1Result[idx] = val;
  22. if (list2.BinarySearch(val) >= 0) l2Result[idx] = val;
  23. if (list3.BinarySearch(val) >= 0) l3Result[idx] = val;
  24.  
  25. idx += 1;
  26. }
  27.  
  28. Console.WriteLine(string.Join("\t", l1Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray()));
  29. Console.WriteLine(string.Join("\t", l2Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray()));
  30. Console.WriteLine(string.Join("\t", l3Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray()));
  31. }
  32. }
  33.  
Success #stdin #stdout 0.04s 37136KB
stdin
Standard input is empty
stdout
1	2	3	4	NULL	NULL	NULL	NULL
NULL	2	3	NULL	5	6	7	8
NULL	NULL	3	4	5	NULL	NULL	NULL