Advertisement
bullit3189

Mixed Up Lists

Jan 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _04MixedUpLists
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<long> firstNums = Console.ReadLine().Split().Select(long.Parse).ToList();
  12. List<long> secondNums = Console.ReadLine().Split().Select(long.Parse).ToList();
  13.  
  14. List<long> result = new List<long>();
  15. List<long> constraints = new List<long>();
  16. List<long> final = new List<long>();
  17.  
  18. if (firstNums.Count>secondNums.Count)
  19. {
  20. for (int i = 0; i < firstNums.Count-2; i++)
  21. {
  22. result.Add(firstNums[i]);
  23. result.Add(secondNums[secondNums.Count - i - 1]);
  24. }
  25.  
  26. constraints.Add(firstNums[firstNums.Count - 2]);
  27. constraints.Add(firstNums[firstNums.Count-1]);
  28.  
  29. long maxConstraint = constraints.Max();
  30. long minConstraint = constraints.Min();
  31.  
  32. for (int i = 0; i < result.Count; i++)
  33. {
  34. long currNum = result[i];
  35.  
  36. if (currNum> minConstraint && currNum<maxConstraint)
  37. {
  38. final.Add(currNum);
  39. }
  40. }
  41. final.Sort();
  42. Console.WriteLine(string.Join(" ",final));
  43. }
  44. else
  45. {
  46. for (int i = 0; i < secondNums.Count-2; i++)
  47. {
  48. result.Add(firstNums[i]);
  49. result.Add(secondNums[secondNums.Count-i-1]);
  50. }
  51.  
  52. constraints.Add(secondNums[0]);
  53. constraints.Add(secondNums[1]);
  54.  
  55. long maxConstraint = constraints.Max();
  56. long minConstraint = constraints.Min();
  57.  
  58. for (int i = 0; i < result.Count; i++)
  59. {
  60. long currNum = result[i];
  61.  
  62. if (currNum > minConstraint && currNum < maxConstraint)
  63. {
  64. final.Add(currNum);
  65. }
  66. }
  67. final.Sort();
  68. Console.WriteLine(string.Join(" ", final));
  69. }
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement