Advertisement
Mitax

4 union list

Feb 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 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. namespace _04.Ununion_Lists
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> listOfInts = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14. int numberOfNewLists = int.Parse(Console.ReadLine());
  15.  
  16. for (int i = 0; i < numberOfNewLists; i++)
  17. {
  18. List<int> listsToCompare = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  19. List<int> differentNumbers = listsToCompare.Except(listOfInts).ToList(); // Adds the different numbers to a list.
  20. List<int> sameNumbers = listsToCompare.Intersect(listOfInts).ToList(); //Adds the same numbers to a list.
  21.  
  22. for (int j = 0; j < differentNumbers.Count; j++)
  23. {
  24. listOfInts.Add(differentNumbers[j]);
  25. }
  26. for (int y = 0; y < sameNumbers.Count; y++)
  27. {
  28. listOfInts.Remove(sameNumbers[y]);
  29.  
  30. if (listOfInts.Contains(sameNumbers[y]))
  31. {
  32. y--;
  33. }
  34. }
  35.  
  36. }
  37. listOfInts.Sort();
  38.  
  39. Console.WriteLine(string.Join(" ", listOfInts));
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement