Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace SoftUniLists
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Enter the first list: ");
- List<int> list1 = ReadList();
- Console.Write("Enter the second list: ");
- List<int> list2 = ReadList();
- int resultListCount;
- int remainingCount = 0;
- if(list1.Count > list2.Count)
- {
- resultListCount = list2.Count;
- remainingCount = list1.Count - list2.Count;
- }
- else
- {
- resultListCount = list1.Count;
- remainingCount = list2.Count - list1.Count;
- }
- List<int> resultList = new List<int>(list1.Count + list2.Count);
- for(int i = 0; i < resultListCount; i++)
- {
- resultList.Add(list1[i]);
- resultList.Add(list2[i]);
- }
- if (list1.Count > list2.Count)
- {
- for(int i = list1.Count - remainingCount; i < list1.Count; i++)
- {
- resultList.Add(list1[i]);
- }
- }
- else
- {
- for (int i = list2.Count-remainingCount; i < list2.Count; i++)
- {
- resultList.Add(list2[i]);
- }
- }
- PrintList(resultList);
- }
- static List<int> ReadList(int n)
- {
- var list = new List<int>();
- for (int i = 0; i < n; i++)
- {
- list.Add(int.Parse(Console.ReadLine()));
- }
- return list;
- }
- static List<int> ReadList()
- {
- List<int> list = new List<int>();
- var line = Console.ReadLine();
- list = line.Split().Select(int.Parse).ToList();
- return list;
- }
- static void PrintList(List<int> list)
- {
- for (int i = 0; i < list.Count; i++)
- {
- Console.WriteLine(list[i]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment