#17. 提取数组首尾元素

    ID: 17 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-1gesp3一维数组字符串

提取数组首尾元素

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 22 containing the first and last elements from the original array. The original array will have a length of 11 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 22, 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 11 and the last element is 33. Therefore, the new array returned is [1, 3].

Constraints

Time limit: 11 second per test case. Memory limit: 10241024 KiB per test case.