Teo_Yanchev

Lists - MergingLists - C# Fundamentals

Sep 13th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _3.MergingLists
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> firstList = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. List<int> secondList = Console.ReadLine()
  17. .Split()
  18. .Select(int.Parse)
  19. .ToList();
  20.  
  21. List<int> result = new List<int>();
  22. int numberFirst = firstList.Count;
  23. int numberSecond = secondList.Count;
  24.  
  25. for (int i = 0; i < Math.Max(firstList.Count, secondList.Count); i++)
  26. {
  27.  
  28. if (numberFirst > 0)
  29. {
  30. result.Add(firstList[i]);
  31. numberFirst -= 1;
  32. }
  33.  
  34. if (numberSecond > 0)
  35. {
  36. result.Add(secondList[i]);
  37. numberSecond -= 1;
  38. }
  39. }
  40.  
  41. Console.WriteLine(string.Join(" ", result));
  42. }
  43. }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment