Въпрос за задача 7. Merging Lists
Здравейте ,
не мога да се справя с тази задача и като цяло нямам идея как да подходя ако може някой да помогне ще съм благодарен !
You are going to receive two lists with numbers. Create a result list which contains the numbers from
both of the lists. The first element should be from the first list, the second from the second list and so
on. If the length of the two lists are not equal, just add the remaining elements at the end of the list.
Example
Input
3 5 2 43 12 3 54 10 23
76 5 34 2 4 12
3 76 5 5 2 34 43 2 12 4 3 12 54 10 23-Output
76 5 34 2 4 12
3 5 2 43 12 3 54 10 23
76 3 5 5 34 2 2 43 4 12 12 3 54 10 23-Output
Благодаря ! решението ти е изключително ясно !
Здравейте,
Това е моето решение!
using System;
using System.Collections.Generic;
using System.Linq;
namespace _03._Merging_Lists
{
class Program
{
static void Main(string[] args)
{
List<double> first = Console.ReadLine()
.Split()
.Select(double.Parse)
.ToList();
List<double> second = Console.ReadLine()
.Split()
.Select(double.Parse)
.ToList();
InputTwoeList(first, second);
}
public static List<double> InputTwoeList(List<double> first, List<double> second)
{
List<double> totalConcatenate = new List<double> ();
int forCycleIteration = Math.Max(first.Count, second.Count);
for (int i = 0; i < forCycleIteration; i++)
{
if (first.Count > i)
{
totalConcatenate.Add(first[i]);
}
if (second.Count > i)
{
totalConcatenate.Add(second[i]);
}
}
Console.WriteLine(string.Join(" ", totalConcatenate));
return totalConcatenate;
}
}
}