Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Extract_Middle_1__2_or_3_Elements
- {
- class Program
- {
- static void Main(string[] args)
- {
- var nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int n = nums.Length;// създавам променлива със стойност дължината на листа
- int[] result;//
- if (n == 1)
- {
- result = new int[1];
- result[0] = nums[0];
- }
- else if (n % 2 == 0)
- {
- result = new int[2];
- result[0] = nums[n / 2 - 1];
- result[1] = nums[n / 2];
- }
- else
- {
- result = new int[3];
- result[0] = nums[n / 2 - 1];
- result[1] = nums[n / 2];
- result[2] = nums[n / 2 + 1];
- }
- Console.WriteLine("{0}, ", result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement