Advertisement
Guest User

Untitled

a guest
Mar 5th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace MixedUpLists
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. //Input
  12. var firstList = Console.ReadLine().Split().Select(int.Parse).ToList();
  13. var secondList = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.  
  15. //Find the smaller length
  16. int k = Math.Min(firstList.Count, secondList.Count);
  17.  
  18. List<int> biggerList = FindTheBiggerList(firstList, secondList);
  19.  
  20. //Find the lower limit and the upper limit
  21. int lowerLimit = Math.Min(biggerList[k], biggerList[k + 1]);
  22. int upperLimit = Math.Max(biggerList[k], biggerList[k + 1]);
  23.  
  24. List<int> commonList = new List<int>();
  25.  
  26. for (int i = 0; i < k; i++)
  27. {
  28. commonList.Insert(2 * i, firstList[i]);
  29. commonList.Insert((2 * i + 1), secondList[k - i - 1]);
  30. }
  31.  
  32. commonList.RemoveAll(x => (x <= lowerLimit || x >= upperLimit));
  33. commonList.Sort();
  34. Console.WriteLine(String.Join(" ", commonList));
  35. }
  36.  
  37. private static List<int> FindTheBiggerList(List<int> firstList, List<int> secondList)
  38. {
  39. if (firstList.Count > secondList.Count)
  40. return firstList;
  41.  
  42. else
  43. return secondList;
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement