Advertisement
bullit3189

Mixed Up Lists -2ndOption - Arrays

Feb 6th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. List<int>first = Console.ReadLine().Split().Select(int.Parse).ToList();
  12. List<int>second = Console.ReadLine().Split().Select(int.Parse).ToList();
  13.  
  14. List<int> limits = new List<int>();
  15. List<int>result = new List<int>();
  16.  
  17. if (first.Count > second.Count)
  18. {
  19. limits.Add(first[first.Count-2]);
  20. limits.Add(first[first.Count-1]);
  21.  
  22. first.RemoveRange(first.Count-2,2);
  23. second.Reverse();
  24.  
  25. for (int i=0; i<first.Count; i++)
  26. {
  27. result.Add(first[i]);
  28. result.Add(second[i]);
  29. }
  30.  
  31. int constr1 = limits[0];
  32. int constr2 = limits[1];
  33. int minConstr = Math.Min(constr1,constr2);
  34. int maxConstr = Math.Max(constr1,constr2);
  35.  
  36. List<int>answer = new List<int>();
  37.  
  38. for (int i=0; i<result.Count; i++)
  39. {
  40. int currNum = result[i];
  41.  
  42. if (currNum>minConstr && currNum<maxConstr)
  43. {
  44. answer.Add(currNum);
  45. }
  46. }
  47. answer.Sort();
  48. Console.WriteLine(string.Join(" ",answer));
  49.  
  50. }
  51. else
  52. {
  53. limits.Add(second[0]);
  54. limits.Add(second[1]);
  55.  
  56. second.RemoveRange(0,2);
  57. second.Reverse();
  58.  
  59. for (int i=0; i<first.Count; i++)
  60. {
  61. result.Add(first[i]);
  62. result.Add(second[i]);
  63. }
  64.  
  65. int constr1 = limits[0];
  66. int constr2 = limits[1];
  67. int minConstr = Math.Min(constr1,constr2);
  68. int maxConstr = Math.Max(constr1,constr2);
  69.  
  70. List<int>answer = new List<int>();
  71.  
  72. for (int i=0; i<result.Count; i++)
  73. {
  74. int currNum = result[i];
  75.  
  76. if (currNum>minConstr && currNum<maxConstr)
  77. {
  78. answer.Add(currNum);
  79. }
  80. }
  81. answer.Sort();
  82. Console.WriteLine(string.Join(" ",answer));
  83. }
  84.  
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement