Advertisement
Guest User

Extract Middle Elements

a guest
May 9th, 2018
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApp5
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. int[] seq = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.  
  13. if (seq.Length == 1)
  14. {
  15. GetMiddleOne(seq);
  16. }
  17. else if (seq.Length % 2 == 0)
  18. {
  19. GetMiddleTwo(seq);
  20. }
  21. else
  22. {
  23. GetMiddleThree(seq);
  24. }
  25.  
  26.  
  27.  
  28.  
  29. }
  30.  
  31. private static void GetMiddleThree(int[] seq)
  32. {
  33. Console.WriteLine($"{{ {seq[seq.Length / 2 - 1]}, {seq[seq.Length / 2]}, {seq[seq.Length / 2 + 1]} }}");
  34. }
  35.  
  36. private static void GetMiddleTwo(int[] seq)
  37. {
  38. Console.WriteLine($"{{ {seq[seq.Length / 2 - 1]}, {seq[seq.Length / 2]} }}");
  39. }
  40.  
  41. private static void GetMiddleOne(int[] seq)
  42. {
  43. Console.WriteLine($"{{ {seq[0]} }}");
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement