Advertisement
skipter

List - Ununion List / remove repatble elements and sort

Jul 12th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _4.Ununion_Lists
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<int> primalList = Console.ReadLine()
  11.                 .Split(' ')
  12.                 .Select(int.Parse)
  13.                 .ToList();
  14.  
  15.             int n = int.Parse(Console.ReadLine());
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 List<int> currentList = Console.ReadLine()
  20.                 .Split(' ')
  21.                 .Select(int.Parse)
  22.                 .ToList();
  23.  
  24.                 for (int cnt = 0; cnt < currentList.Count; cnt++)
  25.                 {
  26.                     int currentElement = currentList[cnt];
  27.                     if (primalList.Contains(currentElement))
  28.                     {
  29.                         primalList.RemoveAll(e => e == currentElement);
  30.                     } else
  31.                     {
  32.                         primalList.Add(currentElement);
  33.                     }
  34.                 }
  35.             }
  36.             primalList.Sort();
  37.             Console.WriteLine(string.Join(" ", primalList));
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement