Advertisement
Kristina_Ivanova

Untitled

Feb 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ME04_Mixed_up_Lists
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             List<int> firstList = Console.ReadLine().
  12.                 Split()
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.             List<int> secondList = Console.ReadLine().
  16.                 Split()
  17.                 .Select(int.Parse)
  18.                 .ToList();
  19.  
  20.             List<int> newList = new List<int>();
  21.             List<int> biggerList = new List<int>();
  22.             int biggerCount = Math.Max(firstList.Count, secondList.Count);
  23.             int firstConstrain;
  24.             int secondConstrain;
  25.             if (biggerCount==firstList.Count)
  26.             {
  27.                 biggerList = firstList;
  28.                 firstConstrain = firstList.Count - 1;
  29.                 secondConstrain = firstList.Count - 2;
  30.             }
  31.             else
  32.             {
  33.                 biggerList = secondList;
  34.                 firstConstrain = 0;
  35.                 secondConstrain = 1;
  36.             }
  37.             int minValue = Math.Min(biggerList[firstConstrain],
  38.                 biggerList[secondConstrain]);
  39.  
  40.             int maxValue = Math.Max(biggerList[firstConstrain],
  41.                 biggerList[secondConstrain]);
  42.             newList.AddRange(firstList.Where(number => (number > minValue && number < maxValue)).ToList());
  43.             newList.AddRange(secondList.Where(number => (number > minValue && number < maxValue)).ToList());
  44.             newList.Sort();
  45.             Console.WriteLine(string.Join(" ",newList));
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement