language: C# (mono-2.8)
date: 180 days 9 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.Linq;
 
public class Test
{
    public static void Main()
    {
        var list1 = new List<int>() { 1, 2, 3, 4 };
        var list2 = new List<int>() { 2, 3, 5, 6, 7, 8 };
        var list3 = new List<int>() { 3, 4, 5 };
        var all = new HashSet<int>(list1.Concat(list2).Concat(list3));
 
        int?[] l1Result = new int?[all.Count];
        int?[] l2Result = new int?[all.Count];
        int?[] l3Result = new int?[all.Count];
        
        int idx = 0;
        foreach (int val in all)
        {
            if (list1.BinarySearch(val) >= 0) l1Result[idx] = val;
            if (list2.BinarySearch(val) >= 0) l2Result[idx] = val;
            if (list3.BinarySearch(val) >= 0) l3Result[idx] = val;
 
            idx += 1;
        }
 
        Console.WriteLine(string.Join("\t", l1Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray()));
        Console.WriteLine(string.Join("\t", l2Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray()));
        Console.WriteLine(string.Join("\t", l3Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray()));
    }
}