skipter icon

List - Ununion List / remove repatble elements and sort

skipter | PRO | 07/12/17 10:57:56 AM UTC | 0 ⭐ | 359 👁️ | Never ⏰ | []
C# |

1.15 KB

|

None

|

0 👍

/

0 👎

using System;
using System.Collections.Generic;
using System.Linq;
namespace _4.Ununion_Lists
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> primalList = Console.ReadLine()
                .Split(' ')
                .Select(int.Parse)
                .ToList();
 
            int n = int.Parse(Console.ReadLine());
 
            for (int i = 0; i < n; i++)
            {
                List<int> currentList = Console.ReadLine()
                .Split(' ')
                .Select(int.Parse)
                .ToList();
 
                for (int cnt = 0; cnt < currentList.Count; cnt++)
                {
                    int currentElement = currentList[cnt];
                    if (primalList.Contains(currentElement))
                    {
                        primalList.RemoveAll(e => e == currentElement);
                    } else
                    {
                        primalList.Add(currentElement);
                    }
                }
            }
            primalList.Sort();
            Console.WriteLine(string.Join(" ", primalList));
        }
    }
}

Comments