Advertisement
StoimenK

C#_Lists_1.3.Merging_Lists

Feb 28th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 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 _1._3.Merging_Lists
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             List<int> firstInput = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.             List<int> secondInput = Console.ReadLine().Split().Select(int.Parse).ToList();
  15.  
  16.             int counter = 0;
  17.  
  18.             if (firstInput.Count > secondInput.Count)
  19.             {
  20.                 counter = firstInput.Count;
  21.             }
  22.             else
  23.             {
  24.                 counter = secondInput.Count;
  25.             }
  26.  
  27.             List<int> endResult = new List<int>();
  28.  
  29.             for (int i = 0; i < counter; i++)
  30.             {
  31.                 if (i < firstInput.Count)
  32.                 {
  33.                     endResult.Add(firstInput[i]);
  34.                 }
  35.                 if (i < secondInput.Count)
  36.                 {
  37.                     endResult.Add(secondInput[i]);
  38.                 }
  39.             }
  40.             Console.WriteLine(string.Join(" ", endResult));
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement