#17. 提取数组首尾元素
提取数组首尾元素
Extract First and Last Elements
Background
Congcong is learning about array operations. He wants to write a program that can quickly extract the first and last elements from a given array.
Problem Description
Given an array of integers, return a new array of length containing the first and last elements from the original array. The original array will have a length of or more.
Input Format
Input is given from Standard Input in the following format.
A single line containing an array of integers. Elements are space-separated and enclosed in square brackets
[].
Output Format
Output is printed to Standard Output in the following format.
A single line containing a new array of length , which includes the first and last elements of the original array. Elements are comma-space separated and enclosed in square brackets
[].
Sample
[1 2 3]
[1, 3]
[1 2 3 4]
[1, 4]
[7 4 6 2]
[7, 2]
Sample Explanation
For the sample input [1 2 3], the first element of the array is and the last element is . Therefore, the new array returned is [1, 3].
Constraints
Time limit: second per test case. Memory limit: KiB per test case.