#29. 提取数组中间三元素
提取数组中间三元素
Middle Three Elements
Background
Congcong is learning array operations and encountered an interesting problem that requires extracting specific elements from a given array.
Problem Description
Given an array of integers of odd length, return a new array of length containing the elements from the middle of the array. The array length will be at least .
Input Format
Input is given from Standard Input in the following format.
A single line containing space-separated integers, representing the elements of the array.
Output Format
Output is printed to Standard Output in the following format.
Output a new array of length with the middle three elements of the original array. The elements should be comma-separated and enclosed in square brackets
[].
Sample
1 2 3 4 5
[2, 3, 4]
8 6 7 5 3 0 9
[7, 5, 3]
1 2 3
[1, 2, 3]
Sample Explanation
For an array of length , the middle element's index is (integer division). We need to extract the three elements at indices , , and .
Constraints
1s, 1024KiB for each test case.