Advertisement
bullit3189

Merging Lists

Feb 4th, 2019
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. List<int>nums = Console.ReadLine().Split().Select(int.Parse).ToList();
  12. List<int>nums2 = Console.ReadLine().Split().Select(int.Parse).ToList();
  13. List<int> merged = new List<int>();
  14.  
  15. if (nums.Count>=nums2.Count)
  16. {
  17. for (int i=0; i<nums.Count; i++)
  18. {
  19. merged.Add(nums[i]);
  20. if (i<nums2.Count)
  21. {
  22. merged.Add(nums2[i]);
  23. }
  24. }
  25. }
  26. else
  27. {
  28. for (int i=0; i<nums2.Count; i++)
  29. {
  30. if (i<nums.Count)
  31. {
  32. merged.Add(nums[i]);
  33. }
  34. merged.Add(nums2[i]);
  35. }
  36. }
  37. Console.WriteLine(string.Join(" ",merged));
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement