Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MixedUpLists
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Input
- var firstList = Console.ReadLine().Split().Select(int.Parse).ToList();
- var secondList = Console.ReadLine().Split().Select(int.Parse).ToList();
- //Find the smaller length
- int k = Math.Min(firstList.Count, secondList.Count);
- List<int> biggerList = FindTheBiggerList(firstList, secondList);
- //Find the lower limit and the upper limit
- int lowerLimit = Math.Min(biggerList[k], biggerList[k + 1]);
- int upperLimit = Math.Max(biggerList[k], biggerList[k + 1]);
- List<int> commonList = new List<int>();
- for (int i = 0; i < k; i++)
- {
- commonList.Insert(2 * i, firstList[i]);
- commonList.Insert((2 * i + 1), secondList[k - i - 1]);
- }
- commonList.RemoveAll(x => (x <= lowerLimit || x >= upperLimit));
- commonList.Sort();
- Console.WriteLine(String.Join(" ", commonList));
- }
- private static List<int> FindTheBiggerList(List<int> firstList, List<int> secondList)
- {
- if (firstList.Count > secondList.Count)
- return firstList;
- else
- return secondList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement