Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Extract_Middle_1__2_or_3_Elements
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14. int n = nums.Length;// създавам променлива със стойност дължината на листа
  15. int[] result;//
  16.  
  17. if (n == 1)
  18. {
  19. result = new int[1];
  20. result[0] = nums[0];
  21. }
  22. else if (n % 2 == 0)
  23. {
  24. result = new int[2];
  25. result[0] = nums[n / 2 - 1];
  26. result[1] = nums[n / 2];
  27. }
  28. else
  29. {
  30. result = new int[3];
  31. result[0] = nums[n / 2 - 1];
  32. result[1] = nums[n / 2];
  33. result[2] = nums[n / 2 + 1];
  34.  
  35. }
  36. Console.WriteLine("{0}, ", result);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement