Advertisement
Razhagal

Join Lists

Mar 31st, 2014
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class JoinLists
  8. {
  9.     static void Main()
  10.     {
  11.         string firstLine = Console.ReadLine();
  12.         string secondLine = Console.ReadLine();
  13.         string[] firstLineNums = firstLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  14.         string[] secondLineNums = secondLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  15.  
  16.         List<int> mainList = new List<int>();
  17.         List<int> auxiliaryList = new List<int>();
  18.  
  19.         for (int i = 0; i < firstLineNums.Length; i++)
  20.         {
  21.             auxiliaryList.Add(int.Parse(firstLineNums[i]));
  22.         }
  23.  
  24.         for (int i = 0; i < secondLineNums.Length; i++)
  25.         {
  26.             auxiliaryList.Add(int.Parse(secondLineNums[i]));
  27.         }
  28.  
  29.         auxiliaryList.Sort();
  30.  
  31.         mainList = auxiliaryList.Distinct().ToList(); //LINQ - Distinct erases the duplicated elements
  32.  
  33.         foreach (int number in mainList)
  34.         {
  35.             Console.Write(number + " ");
  36.         }
  37.         Console.WriteLine();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement