ZhivkoPetkov

ArrLab - Extract Middle 1, 2 or 3 Elements

Apr 17th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 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 ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             int lenght = input.Length;
  15.             if (lenght == 1)
  16.             {
  17.                 Console.WriteLine($"{{ {input[0]} }}");
  18.             }
  19.             else if (lenght % 2 == 0)
  20.             {
  21.                 Console.WriteLine($"{{ {input[lenght/2-1]} {input[lenght / 2]} }}");
  22.             }
  23.             else
  24.             {
  25.                 Console.WriteLine($"{{ {input[lenght / 2 - 1]} {input[lenght / 2]} {input[lenght / 2 + 1]} }}");
  26.             }
  27.     }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment